> $result = mysql_query($query) or die(report($query,__LINE__ ,__FILE__));

> 

> //====================  to show dB errors  ======================

> 

> function report($query, $line, $file)

>     {

>    echo($query . '<br>' .$line . '<br/>' . $file . '<br/>' . 

> mysql_error());

>    }

> 

> This does two things: 1) It tells where the error took place

> (line/file); 2) and it provides a single place in my entire project to

> turn-off dB error reporting -- all I have to do is comment out a single

> line.



I did this, briefly, but got tired of typing __LINE__, __FILE__ so much.



define('ERROR_VERBOSE', 0);

function error_handler($level, $messsage, $file, $line, &$context){

  error_log("$file:$line - $message");

  if (ERROR_VERBOSE){

    foreach($context as $k=>$v){

      error_log("$k: $v");

    }

  }

  switch($level){

    case E_USER_ERROR:

    case E_USER_WARNING:

    case E_USER_NOTICE:

    case E_WARNING:

    case E_NOTICE:

       //do nothing

    break;

    case E_ERROR:

      exit;

    break;

    default:

      error_log("PHP Devs invented a new error level:? " . $level);

    break;

  }

}

set_error_handler('error_handler');

$f = mysql_query($sql) or trigger_error(mysqli_error($connection));



This generalizes it to not be just about DB errors, but ANY php error.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to