DB_common::autoCommit()
DB_common::autoCommit() -- Turns auto-commit on or off
Synopsis
mixed autoCommit (
boolean $onoff = FALSE
)
Description
Turns auto-commit on or off.
Parameter
-
boolean
$onoff
-
TRUE to turn auto-commit on. FALSE to turn auto-commit off.
Return value
integer - DB_OK on success
or a DB_Error object on failure
Throws
Possible PEAR_Error values
Error code |
Error message |
Reason |
Solution |
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.
When using MySQL as your DBMS, transactions can only be used when the
tables in question use the InnoDB format.
Example
Using autocommit()
<?php $db =& DB::connect('ibase(firebird)://user:pw@localhost/path/file');
$db->autoCommit(false);
$db->query('CREATE TABLE blah (a integer)'); $db->query('CREATE TABLE blue (b integer)'); $db->commit();
$db->query('INSERT INTO blah (a) VALUES (11)'); $db->query('INSERT INTO blah (a) VALUES (12)');
$res1 =& $db->query('SELECT a FROM blah'); if (DB::isError($res1)) { echo $res1->getMessage() . "\n"; } $i = 1; while ($res1->fetchInto($row, DB_FETCHMODE_ORDERED)) { echo "fetch data $row[0]\n"; echo "insert number $i...\n"; $res2 =& $db->query("INSERT INTO blue (b) VALUES ($i)"); if (DB::isError($res2)) { echo $res2->getMessage() . "\n"; } $i++; } $res1->free();
$db->query('DROP TABLE blah'); $db->query('DROP TABLE blue'); $db->commit(); ?>
|