- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:reference:connection:replace

# 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,
           string $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 hueristic 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';
    $ar = array('product_code'=>10201,
                'product_name' =>"'Nails'",
                'price' => 3.99);

    $status = $db->replace($tableName,$ar ,$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

v5/reference/connection/replace.txt · Last modified: 2016/01/16 16:57 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top