Skip to content

insertRecord

Ayoob edited this page Apr 11, 2020 · 2 revisions

insertRecord

[easySQLite3 >= v0.1.0 (Beta)]

Insert data to a database using prepared statement.

Description

insertRecord( [ string $table_name [, array $data_array ]] ) : object

This function is used to insert data to a database using prepared statement.

The prepared statement will be applied automatically.

Parameters

Parameter Description
table_name The table name to insert data to.
data_array Array containing the data to insert. Can be taken from the functions setData() and getData().

Return Values

Returns an SQLite3Result object on successful inserting of data, false on failure

Examples

Example #1 : Insert data.

include "easySQLite3.class.php";

$db = new easySQLite3("database.sqlite");

$db->setTable( "TableName" );

$db->clearData();

$db->setData("id", null);                        // Will set null value for the column 'id' as it's auto-incremented.
$db->setData("mail", "[email protected]");        // Will set '[email protected]' for the column 'mail'.
$db->setData("url", "https://example.com");      // Will set 'https://example.com' for the column 'url'.
$db->setData("timestamp", date("Y-m-d H:i:s"));  // Will set the current date for the column 'timestamp' in the format of 'YYYY-MM-DD HH:MM:SS'.
$db->setData("status", 0);                       // Will set '0' for the column 'status'.

if ( $db->insertRecord() ) {
    echo "Data has been added.";
}

Notes

Related Functions

  • setData - Set data to insert into a table, or update a record in a table.
  • getData - Get the temporary data that was created using setData() function.
  • clearData - Clears temporary data that was created using setData() function.
  • isTable - Check if table exits in a database.
  • setTable - Set the default Table name to work with.

Back to Functions list

Clone this wiki locally