I’m using CI3 with sqlite3 as backend database with following configuration:
$db['default'] = array(
'dsn' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => APPPATH.'database/test.db',
'dbdriver' => 'sqlite3',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => false,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Now, I’m able to successfully run queries in code, but the problem comes in error handling. In the below code, for example, even when the query fails, I’m unable to fetch the error code
and message
(code is 0 and message is not an error
). Is there a way to make it throw the actual error message (X constraint failed
, etc.) with code?
$sql = "update employee set email='test@example.com' where id=1";
if (!$this->db->query($sql)) {
$err = $this->db->error();
print_r($err); //code is still 0 :-(
}
Thank you in advance.