Skip to content

Instantly share code, notes, and snippets.

@Asenar
Last active August 29, 2015 14:20
Show Gist options
  • Save Asenar/5e9cea32d588507c9aad to your computer and use it in GitHub Desktop.
Save Asenar/5e9cea32d588507c9aad to your computer and use it in GitHub Desktop.
draft to handle error and ignore mysql deprecated error
<?php
define('DEBUG', true); // true = enable debug mode
define('DEBUG_ALLOW_ERRORS', false); // false = break on every notice/warning/error(throw exception)
set_error_handler('error_handler');
// set_exception_handler(array('Kohana_Exception', 'handler'));
function error_handler($code, $error, $file = NULL, $line = NULL){
if (error_reporting() & $code)
{
if (in_array($code, array(512, 8192)) && preg_match('#mysql_connect#', $error) ){
return true; // return true to skip default error handler
}
if (DEBUG && !DEBUG_ALLOW_ERRORS)
{
throw new ErrorException($error, $code, 0, $file, $line);
}
else
{
if (function_exists('error'))
error($error.' in file "'.$file.'", line '.$line.' [errorCode '.$code.']');
return false; // return false to use default error handler
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment