PHP Mysql PDO 和解锁 table

PHP Mysql PDO and unlock table

如果 php (try/catch) 出现错误,我是否应该管理 table 解锁?或者锁在脚本结束时由 PDO 对象自动释放?

是的。除非您使用的是持久连接,否则在脚本终止时 PDO 将关闭连接,然后 mysql 将释放所有锁:

PHP will automatically close the connection when your script ends.
http://php.net/manual/en/pdo.connections.php

If the connection for a client session terminates, whether normally or abnormally, the server implicitly releases all table locks held by the session (transactional and nontransactional).
https://dev.mysql.com/doc/refman/5.1/en/lock-tables.html