开发者

Print informative, well formatted mysql errors in PHP

Mysql errors are among the most common ones you see during development, and I am searching for a pleasant and informative way to output them.

phpMyAdmin apparently has a decent pretty-printer for mySQL queries:

parsed query http://img706.imageshack.us/img706/2873/clipboard02a.png

However, it prints errors as simple text:

error output http://img683.imageshack.us/img683/1577/clipboard03g.png

Whereas in the latter example, the text after for the right syntax to use near could have been highlighted in the query. Like this:

alt text http://img710.imageshack.us/img710/2839/clipboard03z.png

Even though it's a short query, you immediately see there's a surplus comma right before the text. Doing so in much larger queries could increase readability dramatically, I'm surprised numerous searches on the subject came up with nothing.

Question in one sentence: Do yo开发者_开发技巧u use or know of any such PHP class that displays pretty mysql errors for debugging purposes?


This is really quite trivial for you to do it with a custom function:

function printPrettyError($sql, $error) {
    $display = preg_replace("~^(.*to use near ')(.*)(' at line [0-9]+)$~s", '$1<u>$2</u>$3', $error);
    $display .= "<br />$sql";
}

You will have to tailor it up and decide if you want to make more formatting items to the $sql statement (IE add line breaks before FROM and ORDER BY etc.) But should give you a start.


I'm not sure whether this would work..

All the error messages from mysql are rendered from this file only share/errmsg.txt

Error message information is listed in the share/errmsg.txt file. %d and %s represent numbers and strings, respectively, that are substituted into the Message values when they are displayed.

A sample error message would be , %s near '%s' at line %d

so if we can add something in all the error messages at errmsg.txt , then we can check for the matching string in the string returned by php mysql_error function then make them bold or italic..

I think there is no specific class wrote before..

You should go from scratch and make it to your own server.


Maybe off topic, but I do not think that the most common errors during development are SQL errors. As displaying the errors in generally I have xDebug installed and it handles the "fine" tuning of error messages.


Try http://krumo.sourceforge.net/ from the website:

To put it simply, Krumo is a replacement for print_r() and var_dump(). By definition Krumo is a debugging tool (initially for PHP4/PHP5, now for PHP5 only), which displays structured information about any PHP variable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜