This is an old revision of the document!
← v5:userguide:learn_abstraction:using_execute|Using Execute ^ v5:userguide:learn_abstraction:start_lesson|Start Of Lesson ^
Inserting And Updating Records
AutoExecute
ADOdb provides a helper routine, autoExecute(). AutoExecute() simplifies the task of inserting and updating records by providing a structured, easy to understand methodology.
Inserting A Record
In order to insert a record, it is sufficient to know:
- The name of the table to insert the data into
- The name of the fields to fill
In the following example, the table to update is called people, and the field names in the table are first_name and last_name.
/* * We must declare a variable to hold the name of the table */ $table = 'people'; $record = array(); $record["first_name"] = "Carol"; $record["last_name"] = "Smith"; $db->autoExecute($table,$record,'INSERT'); /* * result executes "INSERT INTO people (first_name,last_name) values ('Carol',Smith')"; */
Updating A Record
To update a record, we must also know how to retrieve the record uniquely, for example there might be a sequence number on the table that uniquely identifies each one. In the following example, the requested record is identified by an id number of 305:
$table = 'people'; $record = array(); $record["first_name"] = "Caroline"; $record["last_name"] = "Jones"; # Update Caroline's lastname from Smith To Jones $db->autoExecute($table, $record, 'UPDATE', 'id = 305'); /* * result executes "UPDATE people SET first_name='Caroline',last_name='Jones' WHERE id=305"; */
Updating Multiple Records
If the record match statement produces a non-unique result set, then ALL records that match will be updated.
"last_name like 'Sm%'";