zend database error output
I cant see my error of Sql. It cuts my queries, and the error is meaningless except it informs there is an error. Like error in statement "select * from o.."
how can I get full query, so i can investigate how the error occured?
I previously wrote a sql function that throws debugging string if sql has error. I though zend'ers have needed and there should exists a code:
if(($error = mysql_error($conn)){
$cagiri=debug_backtrace();
$i=count($cagiri);
And says
[Caller__Function__] => dbSave
[Caller__Class__] => classBasic
[Arguments] => Array
(
[0] => function : loadLinks
[1] =>
[1] => sql error: Duplicate entry 'http://www.istanbulboncugu.com/Lokma' for key 'url'
[2] => query: insert into downloadLinks set `title`= 'Lokma : İstanbul - Avrupa', `url`= 'http://www.istanbulboncugu.com/Lokma', `site`= 'rssSehirFirsati', `status`= 'new'
So I dont dig 30 query, if there is error, Error string shows function that开发者_如何转开发 composed the query. Etc. I think Zend have lacks that kind of awareness. I know zend not prefers hard and log path against smart ways ?!?
I start using that code, if there is error.
function results($q){
$results = Array();
try{
$results = $this->_db->query($q)->fetchAll();
}catch(Exception $e){
var_dump($q);
die($e->getMessage());
}
return $results;
}
If you are using Zend_Db_Select you can get the full created query by doing
$select->__toString();
In reply to your comment, this is how you can get the SQL error message:
try {
$this->db->insert('Users', $array );
} catch (Exception $e){
echo $e->getMessage();
}
精彩评论