Database Abstraction with PEAR - DB::isError
(Page 5 of 7 )
boolean isError (DB_Error $value) |
The error support built into the database abstraction class in PEAR is second to none. When using one of the many database functions, if there is an error an error object will be returned. You can check if the object returned is an error with DB::isError. We can check if a connection attempt returns an error or if a query returns an error. If the object is an error, the function returns true. Otherwise, it returns false. If we determine that we are dealing with an error object, then there are methods of that error object we can use to display the error.
It is always good practice to check for return errors when making connections or querying a database. Here is an example use of DB::isError for testing if a connection was made:
<?php $db = DB::connect($dsn); if (DB::isError($db)) { die ($db->getMessage()); } ?> |
Next: DB::getOne and DB::query() >>
More Database Articles Articles
More By Matt Wade