I'm trying to customize the error handling with PEAR but it seems to me that it doesn't catch all errors. Here's the code:
include 'DB.php';
...
function PearErrorHandler($error)
{
die($error->getMessage());
}
...
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'PearErrorHandler'));
$this->Ora = DB::connect("oci8://$this->OracleUsername:$this->OraclePasswd@$this->OracleDB");
...
Suppose I have the mistake like
DB::connect("oSi8...
. It is catched by the handler with the message DB Error: not found . But if I write a query like
$result = $this->Ora->query"SEWECT * from test);
while ($result->fetchInto($row, DB_FETCHMODE_ASSOC)) {
...
}
which is, obviously, wrong it fails with message Fatal error: Call to undefined function: fetchinto().
What am I doing wrong? In the article about PEAR:😃B there is such example:
<?php
// Define the app environment (this is: what errors you want to output)
define ('DEBUG_ENV', true);
// This function will handle all errors
function handle_pear_error ($error_obj) {
// Be verbose while developing the application
if (DEBUG_ENV) {
die ($error_obj->getMessage()."\n".$error_obj->getDebugInfo());
// Dump a silly message if the site is in production
} else {
die ('Sorry you request can not be processed now. Try again later');
}
}
require_once 'DB.php';
// On error, call the "handle_pear_error" function back
// You can also use an object as pear error handler so:
// setErrorHandling(PEAR_ERROR_CALLBACK, array($object,'method_name');
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');
$db = DB::connect('pgsql://postgres@localhost/site_db');
$res = $db->query('select id from no_table');
// at this point the execution is aborted and the "handle_pear_error"
// function is called with the error object as its first argument
while ($row = $res->fetchRow()) {
...
}
...
?>
In this example the execution is aborted on the line with the bad sql query and I expect my code to do the same. But it doesn't. What's wrong with my code?
Thanks in advance for help.