[PHP/CodeIgniter] Error handling not working seamlessly with sqlite3 database driver

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.

And you sure that query is going to throw an error? Do you have an email field and an id of 1? If no fields match that to update, it is not an error. When you run that query outside of Codeigniter, do you get a constraint failed error?

I am wondering if your query is legit, just not updating anything, so not tripping any kind of constraint error.

I would try running the query outside of codeigniter and see what you get.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.