开发者

Knowing the last mysql error

I run a PHP script which does a lot of mysql work

At some point mysql fa开发者_开发技巧ils, without printing any errors

I'd like to go then to mysql from console, and ask it what was the last error.

How can I do it?

(I'm aware of php's mysql_error(), but I'm looking for mysql command that I can run directly independently of a php script)


You can run

SHOW ERRORS;

And a similar useful one is:

SHOW WARNINGS;

EDIT

Apparently this will only show errors (or warnings) from your own sessions. So I guess it will not suit your purpose (using console to find errors caused by php).

Anyway, you can read the manual for more info (it says nothing about cross session error logging): http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html


I understand that it's too late, but suddenly someone will find this question just like me ... For better debugging, you can save the MySQL query to a text file on the server.

For example, before the request:

$mysql->query("Select x from y where y.x = ".$_GET['yx']);

Write the following lines:

error_log("Select x from y where y.x = ".$_GET['yx']);

And after that you will be able to see all database requests from different sessions in text file.

For better experience:

if (!$mysql->query("Select x from y where y.x = ".$_GET['yx']))
   error_log("Select x from y where y.x = ".$_GET['yx']);
else 
{
   you code here...
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜