|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33117 sqlite_last_error returns always 1 in case of error
Submitted: 2005-05-24 09:08 UTC Modified: 2005-05-25 18:34 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: stephaneey at hotmail dot com Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.0.4 OS: windows & Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
32 - 27 = ?
Subscribe to this entry?

 [2005-05-24 09:08 UTC] stephaneey at hotmail dot com

sqlite_last_error() is supposed to return the error code from SQLite when a SQL statement fails. In case of error, this function returns always 1. So if you do

echo sqlite_error_string(sqlite_last_error()); you always get the same error message description which is:

SQL logic error or missing database. The method "lastError()" of the super class SQLiteDatabase behaves the same way!

This is very annoying because you're warned about the error but you cannot log it correctly in a log file for example nor applying a specific treatment to a specific error

Reproduce code:
/* Using procedural functions */
sqlite_exec('CREATE TABLE a_table(a_col);');
//Creation of a faulty statement
sqlite_exec($db,'INSERT INTO invalid_table VALUES(\'a_value\');') or showError(sqlite_last_error($db));
/*This should return:
no such table : invalid_table...
/*Generation of another error*/
sqlite_query($db,'SELECT b_col FROM a_table;') or showError(sqlite_last_error($db));
/* This should return 
no such column: b_column...
function showError($err_code)
 echo sqlite_error_string($err_code);
 //Will always result in "SQL logic error or missing..."

Expected result:
As mentionned in the code itself, I'd expect to get an appropriate error code in order to :

- Log the errors correctly in an error file
- In case of exceptions handling, take the appropriate action according to the last error

Actual result:
Bad error code returned since it's always the same no matter of what the real error is!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-24 09:10 UTC] stephaneey at hotmail dot com
Correction of a line of code
 [2005-05-25 18:17 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The returned error code is supplied to PHP by SQLite, if you look at the SQLite error codes listed at: (section 1.4) you'd see that value of 1 corresponds to the errors your code generates.
 [2005-05-25 18:34 UTC] stephaneey at hotmail dot com

Indeed, that's actually right. It's a pity that SQLite doesn't return an error code corresponding to the warnings it generates. Just this example:

$db->queryExec('INSERT INTO unknown_table VALUES...') 

will generate a warning of type "no such table unknown_table..." but PHP will get the error code 1 corresponding to "SQL logic error or missing database" which is really a pity since all the wrong SQL statements will end up with such error code!
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 14:01:29 2024 UTC