![]() |
|
|||
|
Hi guys,
Hopefully this isn't a really silly question... But I'm confused as to how to get Zend_Db to report on SQL errors. I know I can use the profiler, but when my application throws an error I would love to see "SQL Error... incorrect syntax...." etc etc. Do I need to use a try/catch block around every piece of SQL? In an semi related question, the profiler returns the SQL query in its unbound state, with ":variables" in place instead of their substituted values. Is this how PDO works or is there a way to see the variables that I've substituted in there. |
|
|||
|
When executing your queires you should put them in try catch blocks to catch any exceptions thrown and deal with them. You can put several queries in a try/catch block.
I use the mysqli adapter and it has the same behaviour. The variables are not replaced till the query is prepared and the parameters sent to the server for processing. HTH Andrew |
|
|||
|
My final solution to this turned out quite nicely, and I hope this will be of some use to other people. I extended the DB adaptor for the db object I was using to contain automatic try/catch error reporting. Here's snippets of the relevant code
[PHP] class NC_Db_Adaptor extends Zend_Db_Adapter_Pdo_Mysql { /** * Wrapper function for query function to allow for nicer debugging * * @param string|Zend_Db_Select $sql The SQL statement with placeholders. * @param array $bind An array of data to bind to the placeholders. * @return Zend_Db_Pdo_Statement * @throws Exception To re-throw PDOException. */ public function query($sql, $bind = array()) { try { return parent::query($sql, $bind); } catch (Exception $e) { //check if website is live or local. if live, email and supress error, if //local then spit out error message including the sql and bind params throw new Exception($e); } } } [/PHP] Hope some people find this useful |
|
|||
|
Quote:
[php] throw $e; //not throw new Exception ($e); [/php] as in your case you loose whole exception trace and there is little to now use of such exception. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |