开发者

PHP hangs on MySQL delete statement

开发者 https://www.devze.com 2023-03-28 16:22 出处:网络
I\'m trying to delete one row of data from a MySQL database (innodb) in a PHP script. But instead of deleting, the PHP script hangs on the query. It\'s a very simple delete statement:

I'm trying to delete one row of data from a MySQL database (innodb) in a PHP script. But instead of deleting, the PHP script hangs on the query. It's a very simple delete statement:

`mysqli_query($conn, 'delete from picture where idPicture = "'. $temp . '"');'

If I echo the delete string and paste it into a MySQL query window the statement executes normally. Debugging with xdebug shows me just the same hanging on the above delete statement.

mysqli_error() gives me an output of :

Lock wait timeout exceeded; try restarting transaction

If I try to close the connection, afterwards I get this error:

Warning: mysqli_close() [function.mysqli-close]: Couldn't fetch mysqli in

I guess that's normal because the connection timed out. I also use the same connection for other delete/select statements and they all perform well.

If someone could explain wha开发者_JAVA百科t I'm doing wrong it would be really appreciated.


Lock wait timeout exceeded; try restarting transaction In other words the table is locked and cannot be accessed. Make sure no other MySQL sessions are accessing this table (there might be some persistent connections hanging for example).

COMMIT/ROLLBACK any other transactions that have anything to do with this table.

Try getting explicit LOCK for deleting.

See more here: http://dev.mysql.com/doc/refman/5.5/en/lock-tables-and-transactions.html


You've got something holding one or more locks on the records you're trying to delete. Could be an active transaction. You'll have to dig through the process list, show innodb status etc.. to figure out which one it is. If it's an InnoDB transaction, the 'show innodb status' will have the transaction data buried in the middle of the output.

Quickest solution is to restart mysql, which'll kill all transactions and locks, but then you'd probably end up having this problem again in short order. You'll have to figure out what's getting that lock, and why it's not being released.

0

精彩评论

暂无评论...
验证码 换一张
取 消