Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > Database API > Methods

Database API: Insert

Scroll Prev Next More

 

Inserts a record into a database.

Syntax

DB::Insert($table, $values)

Arguments

$table

the table into which the data is inserted.

$values

an array with values that you wish to insert.

Return value

No return value.

Example 1

You can insert a record into any table.

 

// Insert a record into the 'Cars' table
 
$data = array();
$data["make"] = "Toyota";
$data["model"]  = "RAV4";
$data["price"] = 16000;
DB::Insert("cars", $data );

Example 2

You can copy the added or edited record into another table. To do so, use this code in the AfterAdd or AfterEdit event:

 

// Copy the record into the 'Copy_of_cars' table
 
$data = array();
$data["make"] = $values["make"];
$data["model"] = $values["model"];
$data["price"] = $values["price"];
DB::Insert("copy_of_cars", $data );

See also:

Database API: Update()

Database API: Delete()

Database API: Select()

About Database API

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software