User's Manual
Adding Error Recovery
5-16 Oracle Database Express Edition 2 Day Plus PHP Developer Guide Beta Draft
$bindvars = array()) {...}
function db_execute_statement($conn, $statement, &$e,
$bindvars = array()) {...}
4. Edit anyco_db.inc. In db_get_page_data() change the call to
db_do_query() to pass down the error parameter $e:
$r = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW, $e, $bindvars);
5. Edit anyco.php. Add an @ prefix to all oci_* function calls.
The @ prefix prevents errors from displaying because each return result is tested.
Preventing errors from displaying can hide incorrect parameter usage which may
hinder testing the changes in this section.
6. Edit anyco.php. Create a function to handle the error information:
function handle_error($message, $err)
{
ui_print_header($message);
ui_print_error($err, $_SERVER['SCRIPT_NAME']);
ui_print_footer(date('Y-m-d H:i:s'));
}
7. Edit anyco.php. Modify all calls to db_* functions to include the additional error
parameter:
Q Change all db_connect() calls to db_connect($err).
Q Change all db_do_query() calls and insert a $err parameter as the fourth
parameter.
Q Change the db_get_page_data() call and insert a $err parameter as the
fifth parameter.
Q Change the db_execute_statement() calls and insert a $err parameter as
the third parameter.
8. Edit anyco.php. Modify construct_departments() to handle errors
returned. The function becomes:
function construct_departments()
{
if (isset($_SESSION['currentdept']) && isset($_POST['prevdept']) &&
$_SESSION['currentdept'] > 1)
$current = $_SESSION['currentdept'] - 1;
elseif (isset($_SESSION['currentdept']) && isset($_POST['nextdept']))
$current = $_SESSION['currentdept'] + 1;
elseif (isset($_POST['showdept']) && isset($_SESSION['currentdept']))
$current = $_SESSION['currentdept'];
else
$current = 1;
$query =
"SELECT d.department_id, d.department_name,
substr(e.first_name,1,1)||'. '|| e.last_name as manager_name,
c.country_name, count(e2.employee_id) as number_of_employees
FROM departments d, employees e, locations l,
countries c, employees e2
WHERE d.manager_id = e.employee_id
AND d.location_id = l.location_id
AND d.department_id = e2.department_id