0

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 ?!?

2 Answers 2

2

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;
}
Sign up to request clarification or add additional context in comments.

Comments

1

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();
}

2 Comments

you can also type echo $select; - same thing.
dude, I meant when there is error. Of course I can print my sqls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.