Jump to content


Photo

Mysql line error reporting


  • Please log in to reply
1 reply to this topic

#1 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 May 2006 - 03:59 AM

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:

Example:
/// 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?!


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 May 2006 - 05:25 AM

Im sorry, but your question makes little sense. You speak of some query handling class 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,
<?php

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

$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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users