Bladescope Posted April 20, 2008 Share Posted April 20, 2008 Hey, back again. Just wondering if there's any way to handle mysql errors that get generated without having to use or die(). I really don't want the script to be killed if an error is generated, so is there a way to stop showing the normal error PHP generates when something goes wrong but to generate something like mysql_error does instead? Thanks in advance, Sean. Link to comment https://forums.phpfreaks.com/topic/101979-mysql-error-handling/ Share on other sites More sharing options...
AndyB Posted April 20, 2008 Share Posted April 20, 2008 $result = @mysql_query($query); if (!$result) { echo "Rats! That query failed"; } Link to comment https://forums.phpfreaks.com/topic/101979-mysql-error-handling/#findComment-521898 Share on other sites More sharing options...
woobarb Posted April 20, 2008 Share Posted April 20, 2008 I like the simplicity of AndyB's way, but here's the way we have it in our CMS: function _db_do_mysql_query($s, $conn) { global $DEBUG_LEVEL; try { if ( !@ ($res = mysql_query($s, $conn)) ) throw new Exception (mysql_error()); } catch (Exception $e) { if($DEBUG_LEVEL >= 1) { echo "MYSQL ERROR: ".$e->getMessage()."<br>"; echo "USING: ".$s."<br>"; } return array(-1, $res); } return array(0, $res); } Link to comment https://forums.phpfreaks.com/topic/101979-mysql-error-handling/#findComment-521902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.