ShoeLace1291 Posted March 7, 2013 Share Posted March 7, 2013 I was tired of having to type out the same code over and over to report mysql errors while indicating where they occur. So I decided to write my own function to handle the errors. However, it doesn't seem to be working properly. function DbQuery($query, $file, $line){ if($execute = mysql_query($query)){ return $execute; } else { return ' <p>You have an error in a mysql query.</p> <p>File: '.$file.'</p> <p>Line: '.$line.'</p> <p>Query: '.$query.'</p> '; } } I tested it out with this bit of code. When everything is ok with the query itself, the function works perfectly. If there is a syntax error, I get a php error saying that mysql_num_rows expects parameter 1 to be resource... which I know why, but I can't figure out how to skip that part, and go right to my custom error. $query = DbQuery(" SELECT member_id, email_address, recieve_member_emails, recieve_admin_emails FROM ".DB_PREFIX."members WHERE member_id = ".$mbr['id']." LIM 1", __FILE__, __LINE__); if(mysql_num_rows($query) > 0){ $member = mysql_fetch_assoc($query); var_dump($member); } Thank you for your time. Link to comment https://forums.phpfreaks.com/topic/275353-custom-mysql-function-w-error-handling/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.