DB_Common::autoExecute()

DB_Common::autoExecute() -- Make automaticaly an insert or update query

Synopsis

require_once 'DB.php';

DB_Result autoExecute (string $table, array $fields_values [, integer $mode = DB_AUTOQUERY_INSERT [, string $where = FALSE]])

Description

autoExecute() build automaticaly an insert or an update sql query and call prepare() and execute() with it. The sql query is build by using autoPrepare(). To call autoExecute, you need only an assoc (key => value) where keys are fields names and values are corresponding values of these fields.  

Parameter

string $table

name of the table

array $fields_values

assoc (key => value), keys are fields names, values are values of these fields

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

DB_Result - a new DB_Result or a DB_Error when fail

Throws

 

Table 20-1. Possible PEAR_Error values

Error codeError messageReasonSolution
DB_ERROR_NEED_MORE_DATANULLYour associative array, which has to contain fields names and their values, is empty.Check and correct your fields_values 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 choosen. 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(), autoPrepare()