PDO's automatic submission is different from MySQL's automatic submission. This means that if you set the value of autocommit to default to 0 in your MySQL configuration, it will not change the default value of PDO::ATTR_AUTOCOMMIT. The default value of PDO::ATTR_AUTOCOMMIT is always true.
Changing the value of PDO::ATTR_AUTOCOMMIT to the same value or any other value that is not a boolean or integer will be ignored. This means that both operations are no-ops:
$pdo = new PDO($dsn, $user, $password); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, true); // 因?yàn)槟J(rèn)值是true $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, 1); // 轉(zhuǎn)換為布爾值true,與默認(rèn)值相同
You can trick it by disabling and enabling PDO::ATTR_AUTOCOMMIT:
$pdo = new PDO($dsn, $user, $password); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false); $pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
This will make two calls to the MySQL server and should set MySQL's autocommit value to 1