This is an old revision of the document!
AutoExecute
Syntax
bool AutoExecute( string $tables, string[] $arrFields, string $mode, optional mixed $where optional bool $forceupdate optional bool $magicq )
$ADODB_QUOTE_FIELDNAMES provides control over the quoting and casing of fieldnames, especially useful when fieldnames contain special characters
Description
AutoExecute can automatically generate and execute INSERT and UPDATE statements on a given table with this function, and is a wrapper for GetInsertSQL() and GetUpdateSQL()
AutoExecute() inserts or updates `$table` given an array of `$arrFields`, where the keys are the field names and the array values are the field values to store. Note that there is some overhead because the table is first queried to extract key information before the SQL is generated. We generate an INSERT or UPDATE based on `$mode` (see below).
$table
The name of the table to update
$arrFields
An associative array of field⇒value pairs
$mode
Legal values for `$mode` are
String | Integer | Constant |
---|---|---|
INSERT | 1 | DB_AUTOQUERY_INSERT |
UPDATE | 2 | DB_AUTOQUERY_UPDATE |
$where
The $where clause is required if $mode == 'UPDATE'.
$forceupdate
Value | Description | Overhead |
---|---|---|
false | (default). Only fields that have been modified are updated | The database record is re-read before update |
true | All fields provided are updated | The constructed statement may be considerably larger |
$magicq
Value | Description |
---|---|
false | Does not attempt to quote special characters in character fields e.g. \0 |
true | Attempts to quote special characters, e.g. \0 becomes \\\0 to allow database insertion |
Usage
AutoExecute($table, $arrFields, $mode, $where=false, $forceUpdate=true,$magicq=false)
Insert example
$table = 'people' $record["firstName"] = "Carol"; $record["lastName"] = "Smith"; $conn->AutoExecute($table,$record,'INSERT'); /* * result executes "INSERT INTO people (firstName,lastName) values ('Carol',Smith')"; */
Update example
$table = 'people' $record["firstName"] = 'Carol'; $record["lasTname"] = 'Jones'; $where = "lastname like 'Sm%'"; $conn->AutoExecute($table,$record,'UPDATE', $where); /* * result executes "UPDATE people SET firstName='Carol',lasTname='Jones' WHERE lastname like 'Sm%'"; */