Jump to content


This topic is now archived and is closed to further replies.


Mysql line error reporting

Recommended Posts

I am trying to build a custom error reporter for mysql. Everything is ok so far but i cant get the linenumber from which the error is. Here is what i have for now:

/// main php file with mysql connection and a linenumber of the row
1256 : $info = mysql_fetch_object($cr_mysql->query('SELECT dor FROM users WHERE id=1'));
/// i want when an error occurs in this query to log the error and the linunumber of the error
/// here is my query handling class:
$result = mysql_query($query, $this->conn);

if (!$result){

$err = "<errorentry>\n";
$err .= "\t<datetime>" .date('Y-m-d H:i:s (T)'). "</datetime>\n";
$err .= "\t<errornum>Mysql Error</errornum>\n";
$err .= "\t<errortype>" . mysql_error() . "</errortype>\n";
$err .= "\t<errormsg>" . $query. "</errormsg>\n";
$err .= "\t<scriptname></scriptname>\n";
$err .= "\t<scriptlinenum></scriptlinenum>\n";
$err .= "</errorentry>\n\n";

error_log($err, 3, 'mysql_log.log');
die('query error - ' . strftime("%d.%m.%Y",time()));
return $result;

/// the class handles the mysql error but i don know from which line the error is?! any help?!

Share this post

Link to post
Share on other sites
Im sorry, but your question makes little sense. You speak of some [i]query handling class[/i] yet I see no classes in your code. Also you might note that php can only give you the __LINE__ number of a php error. MySql has nothing to do with php. You'll need to make this completely yourslef.

A simple example,

    function MyErrror($line,$error) {
        echo "the following sql error has occured on line number $line<br />";

$result = mysql_query("SELECT * FROM example") or MyErrror(256,mysql_error());
Of course this still does not take into account filenames. If you really want to do this properly and your using php5 you would be much better of to impliment exceptions.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.