DB_common::autoCommit() -- Turns auto-commit on or off
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
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
Example 33-1. 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();
?> |
|