开发者

MYSQL Transactions question, with PHP

I would like to use transaction in some critical areas of my code, but really not for everything I do. I just learnt that there is an AUTOCOMMIT value that is set to 1 by default, and I should set it to 0 if I want to START TRANSACTION and COMMIT or ROLLBACK.

  • Is there a better way to handle that autocommit?
  • How do I know if it is set or not ?
  • Does it's value change to AUTOCOMMIT=1 on every page that loa开发者_开发技巧ds?


Using PDO

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
try {
    // do stuff
    $pdo->commit();
} catch (Exception $ex) {
    $pdo->rollBack();
    throw $ex;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜