PDO, mysql, transactions and table locking

后端 未结 3 1076
旧时难觅i
旧时难觅i 2020-12-31 05:00

For fun I am replacing the mysqli extension in my app with PDO.

Once in awhile I need to use transactions + table locking.

In these situations, according to

3条回答
  •  情书的邮戳
    2020-12-31 05:22

    When you call PDO::beginTransaction(), it turns off auto commit.

    So you can do:

    $db->beginTransaction();
    $db->exec('LOCK TABLES t1, t2, ...');
    # do something with tables
    $db->commit();
    $db->exec('UNLOCK TABLES');
    

    After a commit() or rollBack(), the database will be back in auto commit mode.

提交回复
热议问题