Re: error returning with PEAR::DB

From: Date: Tue, 30 Mar 2004 20:16:15 +0000
Subject: Re: error returning with PEAR::DB
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11542@lists.php.net to get a copy of this message
Nelson E. Castillo wrote:
$result =& $db->query('INSERT bla bla...');
// check if an error occurred if (is_a($result, 'DB_error')) {
echo 'Standard Message: ' . $result->getMessage() . "\n".
       'Standard Code: '     . $result->getCode() . "\n".
       'DBMS/User Message: ' . $result->getUserInfo() . "\n".
       'DBMS/Debug Message: ' . $result->getDebugInfo();
} }
Hello. I am new to PEAR myself but I guess this information could help, as it helped me yesterday. You could (but probably should not) parse the DBMS user message to tell what happened. I would prefer to do the query to find out whether the user exists. It will be rather fast if you set an index for the 'username' field -if it's not not your primary key-.
have a look at the error codes in DB.php. then you can use getCode() as I pointed out and see if the error code matches. 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

« previous php.pear.general (#11542) next »