DB_common::autoCommit() -- Turns auto-commit on or off
Beschreibung
Turns auto-commit on or off.
Parameter
- boolean
$onoff
TRUE to turn auto-commit on. FALSE to turn auto-commit off.
Rückgabewert
integer - DB_OK on success
or a DB_Error object on failure
Hinweise
Diese Methode kann nicht
statisch aufgerufen werden.
When using MySQL as your DBMS, transactions can only be used when the
tables in question use the InnoDB format.
Beispiel
Beispiel 34-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();
?> |
|