Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Mysql PDO and unlock table

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?

like image 763
Tobia Avatar asked Apr 23 '26 08:04

Tobia


1 Answers

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:

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

like image 174
Your Common Sense Avatar answered Apr 24 '26 21:04

Your Common Sense