DB_common::autoCommit() -- Turns auto-commit on or off
Opis
Turns auto-commit on or off.
Parametr
- boolean
$onoff
TRUE to turn auto-commit on. FALSE to turn auto-commit off.
Zwracana wartość
integer - DB_OK on success
or a DB_Error object on failure
Uwagi
Ta funkcja nie może być wywołana
statycznie.
When using MySQL as your DBMS, transactions can only be used when the
tables in question use the InnoDB format.
Przykład
Przykład 35-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();
?>
|
|