ADOdb Lite How to Install

| Error Handling

PHP 5 Exception Handling using adodb-exceptions.inc.php.

include("../adodb-exceptions.inc.php");
include("../adodb.inc.php");
try
{
$db = NewADOConnection("mysql://test:password@mine/");
}
catch (exception $e)
{
var_dump($e);
}

Standard Error Handling using adodb-errorhandler.inc.php.

This uses the standard PHP error_reporting to control the error messages display or store through the PHP trigger_error function.

The error handler will be triggered when a Connect(), PConnect(), Execute() or SelectLimit() fails or causes an error.

The adodb-errorhandler.inc.php should be included before you create any ADOConnection objects.

If you define error_reporting(0), no errors will be passed to the error handler. If you set error_reporting(E_ALL), all errors will be passed to the error handler. You still need to use ini_set("display_errors", "0" or "1") to control the display of errors.

You can log your error messages by defining the following optional constants ADODB_ERROR_LOG_TYPE and ADODB_ERROR_LOG_DEST.
ADODB_ERROR_LOG_TYPE is the error log message type (see error_log in the PHP manual).

ADODB_ERROR_LOG_DEST is the directory path and filename of the location and file you would like the error messages stored..

error_reporting(E_ALL); //Enable reporting of all errors by PHP
include("../adodb-errorhandler.inc.php");
include("../adodb.inc.php");
define('ADODB_ERROR_LOG_TYPE', 3);
define('ADODB_ERROR_LOG_DEST', 'adodb_errors.log');
$db = NewADOConnection('mysql');
$db->Connect('localhost', 'root', '', 'test');
$resultset = $db->Execute('select * from test_table'); // Table named test_table is missing

The following will be stored in the adodb_errors.log file:

    (2006-3-31 03:32:51) mysql error: [1146: Table 'test.test_table' doesn't exist] in
     EXECUTE("select * from test_table")

Pear Style Error Handling using adodb-errorpear.inc.php.
This will create a PEAR_Error object whenever an error occurs. The last PEAR_Error object created can be retrieved using ADODB_Pear_Error().

error_reporting(E_ALL); //Enable reporting of all errors by PHP
include("../adodb-errorpear.inc.php");
include("../adodb.inc.php");
$db = NewADOConnection('mysql');
$db->Connect('localhost', 'root', '', 'test');
$resultset = $db->Execute('select * from test_table'); // Table named test_table is missing
if(!$resultset)
{
$error_object = ADODB_Pear_Error();
echo '<b>' . $error_object->message . '</b>';
}

Copyright ©2005, 2006 Mark Dickenson