Documente Academic
Documente Profesional
Documente Cultură
error_reporting($level)
This function can be used to control which
errors are displayed, and which are simply
ignored. The effect only lasts for the
duration of the execution of your script.
$db = @mysql_connect($h,$u,$p);
if (!$db) {
trigger_error(‘blah’,E_USER_ERROR);
}
$db = @mysql_connect($h,$u,$p);
if (!$db) {
trigger_error(blah.',E_USER_ERROR);
}
Attempt to connect to
database. Suppress error
notice if it fails..
PHP Workshop ›#‹
Since error is suppressed,
2. Suppressing it
Errors
must be handled gracefully
somewhere else..
$db = @mysql_connect($h,$u,$p);
if
if (!$db)
(!$db) {{
trigger_error(blah.',E_USER_ERROR);
trigger_error(‘blah’,E_USER_ERROR);
}
The
echo ‘Anhandler mustoccurred!<br
error has have 4 inputs..
/>’;
1.error
echo “file:code
$file<br />”;
echo “line:
2.error $lineno<br />”;
message
echo “Problem:
3.file $errmsg”;
where error occurred
return
4.linetrue;
at which error occurred
}
echo ‘An
echo ‘An error
error has
has occurred!<br
occurred!<br />’;
/>’;
echo “file:
echo “file: $file<br
$file<br />”;
/>”;
echo
echo “line:
“line: $lineno<br
$lineno<br />”;
/>”;
echo
echo “Problem:
“Problem: $errmsg”;
$errmsg”;
return true;
}
Any PHP statements can be
executed…
PHP Workshop ›#‹
3. Custom Error Handler
function err_handler(
$errcode,$errmsg,$file,$lineno) {