Should I manage the table unlock in case of an error in php (try/catch)? Or the lock is automatically released by PDO object ad the end of the script?
如果php(try / catch)出错,我应该管理表解锁吗?或者PDO对象和脚本结束时会自动释放锁?
1 个解决方案
#1
2
Yes. Unless you're using a persistent connection, on the scripts's termination PDO will close the connection, and mysql, in turn will release all locks:
是。除非你使用持久连接,否则在脚本终止时PDO将关闭连接,而mysql反过来将释放所有锁:
PHP will automatically close the connection when your script ends.
http://php.net/manual/en/pdo.connections.php当脚本结束时,PHP将自动关闭连接。 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如果客户端会话的连接终止,无论是正常还是异常,服务器都会隐式释放会话持有的所有表锁(事务性和非事务性)。 https://dev.mysql.com/doc/refman/5.1/en/lock-tables.html
#1
2
Yes. Unless you're using a persistent connection, on the scripts's termination PDO will close the connection, and mysql, in turn will release all locks:
是。除非你使用持久连接,否则在脚本终止时PDO将关闭连接,而mysql反过来将释放所有锁:
PHP will automatically close the connection when your script ends.
http://php.net/manual/en/pdo.connections.php当脚本结束时,PHP将自动关闭连接。 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如果客户端会话的连接终止,无论是正常还是异常,服务器都会隐式释放会话持有的所有表锁(事务性和非事务性)。 https://dev.mysql.com/doc/refman/5.1/en/lock-tables.html