Re: DB and INSERT's allready exists?

From: Date: Wed, 13 Jul 2005 18:09:30 +0000
Subject: Re: DB and INSERT's allready exists?
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19979@lists.php.net to get a copy of this message
Am Mittwoch, den 13.07.2005, 10:04 -0700 schrieb Justin Patrin: > Why? Because it's always good sense to check for all possible errors > before processing your data. However, even if you do the select it's > still possible for an error to happen (say two people register with > the same e-mail at the same moment in time, the selects will go > through fine, one user will register, the other will get an INSERT > error). > > You should be checking for an error return from whatever DB > abstraction layer you're using. Assuming DB: > $ret = $db->query('INSERT INTO users (email) VALUES > ('.$db->quoteSmart($emailAddress).')'); > if (PEAR::isError($ret)) { > if ($ret->getCode() == DB_ERROR_CINSTRAINT) { > echo 'This email address has been used before'; > } else { > echo 'There has been an error'; > mail('admin@example.com', 'Error in user insert', print_r($ret, true)); > } > } else { > //go on > } Thats exacly what I'm doing. There is no select before, I would say a select is overhead in this case. I'm used to work with errors by using python. There we do many exceptions (like php5 has? im not sure). Thats the way to use the errors for someones case. And here its the same to. Martin

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