DB_Error – DB Error object


In case of failure, most of the DB functions return a DB_Error object which contains information about the error. DB_Error offers the same functions as PEAR_Error.

The text messages returned by DB_Error::getMessage() are consistent between each DBMS.

The error code integers returned by DB_Error::getCode() are also consistent between each DBMS. The integers returned are based on the DB_ERROR_* constants defined in DB.php.

DB_Error::getDebugInfo() and DB_Error::getUserInfo() return complete native DBMS error reports.

Trapping errors and determining what happened

require_once 'DB.php';

$db =& DB::connect('pgsql://wronguser:badpw@localhost/thedb');
if (
PEAR::isError($db)) {
     * This is not what you would really want to do in
     * your program.  It merely demonstrates what kinds
     * of data you can get back from error objects.
echo 'Standard Message: ' $db->getMessage() . "\n";
'Standard Code: ' $db->getCode() . "\n";
'DBMS/User Message: ' $db->getUserInfo() . "\n";
'DBMS/Debug Message: ' $db->getDebugInfo() . "\n";
Gets number of rows in a result set (Previous) DB_DataObject (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.