replace
This function does no row-locking, so it is possible that the same record could be inserted twice by two programs. Use in multi-user environments is not recommended.
syntax
int replace( string $table, mixed $dataFields, mixed $keyColumn, optional bool $autoQuote = false, optional bool $primaryKeyIsAuto=false )
Description
The function replace()
inserts or replace a single record. It can be considered a companion program to autoExecute().
Parameters
$table
The table name to update
$dataFields
An associative array of data, where the keys are the column names and the values are the values to insert or replace. (you must quote strings yourself).
$keyColumn
The primary key field name or if compound key, an array of field names
$autoQuote
Set this value to true to use a heuristic to quote strings. Works with nulls and numbers but does not work with dates nor SQL functions.
$primaryKeyIsAuto
If the primary key is an auto-inc field, skip in insert.
Return Values
returns 0 = fail, 1 = update, 2 = insert
Usage
/* * Connection assumed */ * $tableName = 'products'; $indexColumn = 'product_code'; $data = array('product_code'=>10201, 'product_name' =>"'Nails'", 'price' => 3.99); $status = $db->replace($tableName, $data, $indexColumn); /* * Status code tells us if operation succeeded */
Technical Overview
This is not the same as MySQL's replace. ADOdb's Replace() uses update-insert semantics, not insert-delete-duplicates of MySQL. Also note that no table locking is done currently, so it is possible that the record be inserted twice by two programs…
Currently blob replace not supported