DB_Error

DB_Error – DB Error object

Description

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

<?php
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";
    echo 
'Standard Code: ' $db->getCode() . "\n";
    echo 
'DBMS/User Message: ' $db->getUserInfo() . "\n";
    echo 
'DBMS/Debug Message: ' $db->getDebugInfo() . "\n";
    exit;
}
?>
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.