mysql - Catching exceptions for "INSERT … ON DUPLICATE KEY UPDATE" workaround in ZF -


zf 1.9.5 here. suggested catching exceptions emulate on duplicate key update when using zend_db_table.

currently, i'm getting

sqlstate[23000]: integrity constraint violation: 1062 duplicate entry 'i7dd30253497cfc0539d7c5830a926f7d' key 'ukey'

..when using

$orderrow = $this->createrow(); $orderrow->ukey = $ukey; $orderrow->save(); 

so, want catch bugger try / catch. on exception update , else insert.
don't know catch. zend_db_exception? pdoexception? zend_db_adapter_exception? i've tried several, don't think got it.


later edit. worked me:

        try {             $orderrow = $this->createrow();             $orderrow->ukey = $ukey;             $orderrow->$stepcol = time();             $orderrow->save();         } catch (zend_db_statement_exception $e) {             // on unique error, update             if ($e->getcode() == 23000) {                 $orderrow = $this->fetchrow($this->select()->where('ukey = ?', $ukey));                 $orderrow->$stepcol = time();                 $orderrow->save();             }         } 

just exception getting thrown this:

try {     // query } catch (exception $e) {     var_dump(get_class($e)); } 

that should tell kind of exception need catch because "exception" catch every type of exception, zf exception or pdo exception or different


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -