DB_common::autoExecute() --
Prepares and runs an INSERT or UPDATE query
based on variables you supply
ïÐÉÓÁÎÉÅ
Automatically prepares and executes INSERT or
UPDATE queries.
This method builds a SQL statement using
autoPrepare() and then executes
the statement using
execute() with it.
ðÁÒÁÍÅÔÒ
- 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 clause
÷ÏÚ×ÒÁÝÁÅÍÏÅ ÚÎÁÞÅÎÉÅ
integer - DB_OK on success
or a DB_Error object on failure
Throws
Таблица 22-1. ÷ÏÚÍÏÖÎÙÅ ÚÎÁÞÅÎÉÑ PEAR_Error Error code | Error message | Reason | Solution |
---|
DB_ERROR_NEED_MORE_DATA |
insufficient data supplied
|
Your associative array, which has to contain fields names
and their values, is empty.
|
Check and correct your fields_values array.
| DB_ERROR_SYNTAX |
syntax error
|
You use an unknown mode.
|
Available modes are only
DB_AUTOQUERY_INSERT for
INSERT queries or
DB_AUTOQUERY_UPDATE for
UPDATE queries.
| DB_ERROR_NODBSELECTED |
no database selected
| No 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.
|
úÁÍÅÔËÁüÔÁ ÆÕÎËÃÉÑ ÎÅ ÄÏÌÖÎÁ ×ÙÚÙ×ÁÔØÓÑ ÓÔÁÔÉÞÅÓËÉ. ðÒÉÍÅÒПример 22-1. Using autoExecute()
<?php
// Once you have a valid DB object named $db...
$table_name = 'user';
$fields_values = array(
'id' => 1,
'name' => 'Fabien',
'country' => 'France'
);
$res = $db->autoExecute($table_name, $fields_values,
DB_AUTOQUERY_INSERT);
if (DB::isError($res)) {
die($res->getMessage());
}
?>
|
|
|