Jump to content

Mysql line error reporting


DarkReaper

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:

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?!
Link to comment
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,
[code]
<?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());
[/code]
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.