Whenever I needed a transaction in MySql, I have used PDO::beginTransaction() several times without any issues. However, when I needed to lock tables and still use transactions, I found that
according to this https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html.
But the above reference also states that "The correct way to use LOCK TABLES and UNLOCK TABLES with transactional tables, such as InnoDB tables, is to begin a transaction with SET autocommit = 0 (not START TRANSACTION) followed by LOCK TABLES, and to not call UNLOCK TABLES until you commit the transaction explicitly"
I understand that SET autocommit = 0
and START TRANSACTION
are technically the same in MySql. Correct me on this. But MySql reference above says to use
SET autocommit=0;
LOCK TABLES t1 WRITE, t2 READ, ...;
... do something with tables t1 and t2 here ...
COMMIT;
UNLOCK TABLES;
Now instead of that, can one also use
PDO::beginTransaction();
LOCK TABLES ...;
PDO::commit();
UNLOCK TABLES;
Since PHP PDO::beginTransaction() manual states "Turns off autocommit mode"?