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.
int replace( string $table, string $dataFields, mixed $keyColumn, optional bool $autoQuote = false, optional bool $primaryKeyIsAuto=false )
replace() inserts or replace a single record. It can be considered a companion program to autoExecute().
The table name to update
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).
The primary key field name or if compound key, an array of field names
Set this value to true to use a hueristic to quote strings. Works with nulls and numbers but does not work with dates nor SQL functions.
If the primary key is an auto-inc field, skip in insert.
returns 0 = fail, 1 = update, 2 = insert
/* * Connection assumed */ * $tableName = 'products'; $indexColumn = 'product_code'; $ar = array('product_code'=>10201, 'product_name' =>"'Nails'", 'price' => 3.99); $status = $db->replace($tableName,$ar ,$indexColumn); /* * Status code tells us if operation succeeded */
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