Insert - adampatterson/Tentacle GitHub Wiki

###A Simple insert Inserting data into a table is very easy:

// Select the table
$table = db('mytable');

// Query the database
$table->insert(array(
  'user'=>'Evan',
  'email'=>'[email protected]'
));

The above is the same as the following SQL:

INSERT INTO `mytable` (`user`,`email`) VALUES ('Evan','[email protected]')

Note that the values 'Evan' and '[email protected]' are automatically cleaned of any possible SQL Injections.

Get Inserted Row

Insert also returns the new row inserted:

$row = $table->insert(array(
  'user'=>'Evan',
  'email'=>'[email protected]'
));

// Get the value of the AUTO_INCREMENTING column
echo $row->id;

This functionality can be disabled in order to improve peformance by setting the optional second argument to FALSE.

$table->insert(array(
  'user'=>'Evan',
  'email'=>'[email protected]'
),FALSE);