Reputation: 2814
I am trying to use transactions in the Zend Framework and have a working script.
However, under testing I noticed that a try/catch function will catch any exception except one caused by the Mysql server being inactive.
Is this supposed to happen? If my server crashes I am worried that an ugly Zend exception would be returned and the application would cease to fail gracefully.
My code looks like this:
function insertInbox ($userId, $mail_id )
{
$db = Zend_Db_Table::getDefaultAdapter();
$table = new Application_Model_DbTable_Inbox;
try {
$db->beginTransaction();
$data = array (
'user_id' => $userId,
'mail_id' => $mail_id
);
$insertedId[] = $table -> insert($data);
$db -> commit();
return $insertedId;
}
catch(exception $e){
$db->rollback();
return "insert failed";//.$e;
}
}
$tt = insertInbox ( 666,666);
print_r($tt);
A duplicate entry of similar exception is caught and the temporary custom error message -insert failed- is returned. But if I turn off the database server the php catch does not capture this error:
**Message:** SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
Any thoughts appreciated.
Upvotes: 0
Views: 226
Reputation: 31657
Some database extensions of PHP try to create a database connection when none is established and a function is called, that requires one. In this case $db->rollback()
itself throws an exception.
Upvotes: 1