DarkReaper Posted May 20, 2006 Share Posted May 20, 2006 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 row1256 : $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?! Quote Link to comment https://forums.phpfreaks.com/topic/10049-mysql-line-error-reporting/ Share on other sites More sharing options...
trq Posted May 20, 2006 Share Posted May 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10049-mysql-line-error-reporting/#findComment-37378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.