Here's a useful function.
It logs to the apache error log.
When you want to see the errors in the browser add the line below to the script.
define(DISPLAY_MYSQL_ERRORS,1);
// ---------------------------------------------------------------------------
// -- logs to syslog use like this: log_mysql_error($sql,__FILE__,__LINE__);
// $sql, file and line are optional. __FILE__,__LINE are php magic constants
// ----------------------------------------------------------------------------
function log_mysql_error($sql='',$file='',$line=0) {
global $HTTP_SERVER_VARS;
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$msg = "MySQL Says: " . mysql_error();
error_log($msg,0);
if (1 == DISPLAY_MYSQL_ERRORS) {
echo "$msg
\n";
}
if (!empty($sql)) {
$msg="$PHP_SELF: (FILE=$file) (LINE=$line)\n SQL Statement was: $sql";
error_log($sql,0);
if (1 == DISPLAY_MYSQL_ERRORS) {
$msg="$PHP_SELF: (FILE=$file) (LINE=$line)\n
SQL Statement was: $sql";
echo "$msg\n";
}
}
exit;
}