DB_Common::autoPrepare()

DB_Common::autoPrepare() -- Build automaticaly an insert or an update sql query

Synopsis

require_once 'DB.php';

resource autoPrepare (string $table, array $table_fields, integer $mode = DB_AUTOQUERY_INSERT [, string $where = FALSE])

Description

autoPrepare() build automaticaly an insert or an update sql query and call prepare() with it. The sql query is build by using an ordered array containing fields names.

Parameter

string string $table

name of the table

array $table_fields

ordered array containing the fields names

integer $mode

type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)

string $where

in case of update queries, this string will be put after the WHERE statement

Return value

resource - resource handle for the query

Throws

Table 20-1. Possible PEAR_Error values

Error codeError messageReasonSolution
DB_ERROR_NEED_MORE_DATANULL The ordered array, which has to contain fields names, is empty. Check and correct your fields names array.
DB_ERROR_SYNTAXNULLYou use an unknown mode. Available modes are only DB_AUTOQUERY_INSERT for "insert queries" or DB_AUTOQUERY_UPDATE for "update queries".
DB_ERROR_NO_DB_SELECTEDNULLNo database was chosen. Check the DSN in connect().
every other error code  Database specific error Check the database related section of PHP-Manual to detect the reason for this error.

Note

This function can not be called statically.

See "Introduction - autoPrepare and autoExecute" for general using and an example.

See

prepare(), execute(), executeMultiple(), autoExecute()