forked from adampatterson/Tentacle
-
Notifications
You must be signed in to change notification settings - Fork 1
Insert
Adam Patterson edited this page Dec 18, 2012
·
1 revision
###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'=>'not_real@gmail.com'
));
The above is the same as the following SQL:
INSERT INTO `mytable` (`user`,`email`) VALUES ('Evan','not_real@gmail.com')
Note that the values 'Evan' and 'not_real@gmail.com' are automatically cleaned of any possible SQL Injections.
Insert also returns the new row inserted:
$row = $table->insert(array(
'user'=>'Evan',
'email'=>'not_real@gmail.com'
));
// 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'=>'not_real@gmail.com'
),FALSE);