Zend_Db_Statement_Exception
Posted: Tue Sep 18, 2007 2:10 pm
I've got some php to insert a vendor into my vendors database. It looks like this (I'm using the Zend Framework)...
See the todo in there? Is there a better way to find out if I am getting mysql error code 1062 with this? I know I could do mysql_errno(), but it seems like the Exception would provide this code or at least its own code for that. Do I have to subclass it? Should I just shut up and use mysql_errno()?
Code: Select all
// snip
if ($clean = $this->processInput($input))
{
require_once 'models/Vendors.php';
require_once 'Zend/Db/Expr.php';
$vendor = new Bag_Vendors();
$clean['created'] = new Zend_Db_Expr('NOW()');
try {
$vendor->insert($clean);
$this->_redirect('vendors/view');
}
catch (Zend_Db_Statement_Exception $e) {
if (strstr($e->getMessage(), '1062')) //@todo: find a better way to do this
{
$this->view->formSetError('code', 'This code already exists');
}
}
}
//snip