< Portability: Error Mapping   (Previous) Table of Contents (Next)   Portability: Delete Count >

Portability: Error Mapping Example

require_once './examples/connect.inc';

$$dbms->query('CREATE TABLE tbl (c CHAR(10) NOT NULL)');
$result =& $$dbms->query('INSERT INTO tbl VALUES (NULL)');

if ($result->getMessage() ==
    'DB Error: null value violates not-null constraint')
{
    echo 'Phew, the pointy-haired guy went away!';
} else {
    echo 'AAAAGH! ' . $result->getMessage();
}

$$dbms->query('DROP TABLE tbl');
Default Behavior
$dbms = 'mysql'; $dbms = 'oracle';
AAAAGH! DB Error: constraint violation Phew, the pointy-haired guy went away!
$$dbms->setOption('portability', DB_PORTABILITY_ERRORS);
$dbms = 'mysql'; $dbms = 'oracle';
Phew, the pointy-haired guy went away! Phew, the pointy-haired guy went away!