在使用MySQL时,印象中Innodb表无法进行事务之间的嵌套,其实是有条件的:同一个连接里的事务无法嵌套,但不同连接之间的事务却可以嵌套。
getMessage() . "\n";
}
try {
$dbh->beginTransaction();
if (true) {
$dbh2->beginTransaction();
$dbh2->commit();
}
$dbh->commit();
echo "It's OK.\n";
} catch (Exception $e) {
echo "Transaction Faild: " . $e->getMessage() . "\n";
}
?>
当然,如果使用不同的用户名连接数据库,也是一种方法。