⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactions.inc

📁 apache windows下的一款好
💻 INC
字号:
<?php

// View the table from a separate connection so we don't disturb
// the transaction.
$dbh2 = DB::connect($dbh->dsn);

function dumptable() {
    global $dbh, $dbh2;
    printf("%s ops=%d\n", implode(" ", $dbh->getCol("SELECT b FROM phptest")),
           $dbh->transaction_opcount);
}
$dbh->setErrorHandling(PEAR_ERROR_DIE);
$dbh->autoCommit(true);
$dbh->query("INSERT INTO phptest VALUES(1, 'one', 'One', '2001-02-19')");
print "after autocommit: ";
dumptable();
$dbh->autoCommit(false);
$dbh->query("INSERT INTO phptest VALUES(2, 'two', 'Two', '2001-02-20')");
$dbh->query("INSERT INTO phptest VALUES(3, 'three', 'Three', '2001-02-21')");
print "before commit: ";
dumptable();
$dbh->commit();
print "after commit: ";
dumptable();
$dbh->query("INSERT INTO phptest VALUES(4, 'four', 'Four', '2001-02-22')");
$dbh->query("INSERT INTO phptest VALUES(5, 'five', 'Five', '2001-02-23')");
print "before rollback: ";
dumptable();
$dbh->rollback();
print "after rollback: ";
dumptable();
$dbh->autoCommit(true);
$dbh->query("INSERT INTO phptest VALUES(6, 'six', 'Six', '2001-02-24')");
$dbh->query("INSERT INTO phptest VALUES(7, 'seven', 'Seven', '2001-02-25')");
print "before autocommit+rollback: ";
dumptable();
$dbh->rollback();
print "after autocommit+rollback: ";
dumptable();

print "testing that select doesn't disturbe opcount: ";
$dbh->autoCommit(false);
$dbh->simpleQuery("SELECT * FROM phptest");
$dbh->simpleQuery("SELECT a,c FROM phptest");
$dbh->simpleQuery("SELECT b,d FROM phptest");
if ($dbh->transaction_opcount == 0) {
    print "ok\n";
} else {
    print "failed (count=$dbh->transaction_opcount)\n";
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -