Jump to content

Mysql error handling


Bladescope

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.