Re: error returning with PEAR::DB
| From: | Lukas Smith | Date: | Tue, 30 Mar 2004 20:05:27 +0000 |
| Subject: | Re: error returning with PEAR::DB | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11540@lists.php.net to get a copy of this message | ||
Torsten Roehr wrote:
Hi Pupeno, if the PEAR error handling is set to PEAR_ERROR_RETURN (default mode) you can do: // open connection bla bla // process query $result =& $db->query('INSERT bla bla...'); // check if an error occurred if (is_a($result, 'DB_error')) {this should be: if(DB::isError($result)) {
// set a warning for the user that the user name exists } else { // continue your process } The only problem I see is that you cannot check WHICH error occurred. So if your INSERT query has an incorrect syntax you won't recognize it as the result would be the same as with an existing key in your table. A better way would be to write a small function named userNameExists() that makes a select query and looks for the user name. You could even make it more general and call it recordSetExists() and use it for various tables and columns by passing an array with the required values like table name, column name and so on. This works quite well for me.sure you can .. $error->getCode(); to yet an error code .. http://pear.php.net/manual/en/package.database.db.db-error.php regards, Lukas Smith smith@backendmedia.com _______________________________ BackendMedia www.backendmedia.com berlin@backendmedia.com Linn Zwoch Smith GbR Pariser Str. 44 D-10707 Berlin Tel +49 30 83 22 50 00 Fax +49 30 83 22 50 07