mixed autoCommit (
boolean $onoff
= false
)
Turns auto-commit on or off.
$onoff
TRUE to turn auto-commit on. FALSE to turn auto-commit off.
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. |
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.
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();
?>