2009年2月23日星期一

Re: [fw-db] How do I return SQL query on exception or error

maxarbos wrote:
>
> I would like something that is hooked into the exceptions of ZF as I dont
> know where this error is being thrown from.
>
> Thanks though.
>
>

Yeah, I actually subclassed Zend_Db_Statement_Pdo so that it always throws
exceptions containing not only the SQL, but the parameter values. I also
created a My_Db_Exception class so store the extended info.

My global exception then catches the exception and sends the info by email.

Anyhow, I did override the execute method in Zend_Db_Statement_Pdo, with
something like this:

public function execute(array $params = null) {
if (is_array($params)) {
$this->_bindParam = $params;
}
try {
return parent::execute($params);
}
catch (Exception $e) {
$exDb = new Opale_Db_Exception($e->getMessage(), $e->getCode());
$exDb->setArrayBindValues($this->_bindParam);
$exDb->setSqlQuery($this->sql);
throw $exDb;
}
}

I then have my own Zend_Db_Adapter which will use this Statement class
instead of the default one.
--
View this message in context: http://www.nabble.com/How-do-I-return-SQL-query-on-exception-or-error-tp22166018p22169269.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: