CodeIgniter Forums
how to check for sql syntax error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to check for sql syntax error (/showthread.php?tid=66812)



how to check for sql syntax error - cupboy1 - 12-06-2016

This is the code

      $q = $this->db->query($sql);
      if ($q === FALSE)
        //throw new Exception($this->db->error);  
        throw new Exception('stupid error'); 


It does not work. All that happen is the error is logged by codeignitor and the script is dead at that point. What am I doing wrong?

I may have posted a similar question earlier but I cannot locate it.

UPDATE: I have fixed the problem by modifying some apparently bad code in DB_driver.php that was causing the script to blow up when it attempted this: $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql))
I commented that line out so that query() will return FALSE if the SQL fails. Works fine for me now anyway...


RE: how to check for sql syntax error - Wouter60 - 12-07-2016

Maybe this will help:
http://stackoverflow.com/questions/3234564/under-codeigniter-is-it-possible-to-see-mysql-error