Error with SQLiteDatabase->lastError()

liunx

Guest
Hello All,

I'm using PHP5.0.4 and SQLite. According to the official documentation the method "lastError" of the "SQLiteDatabase" super class is supposed to return the last error code of SQLite.

I'm now developing a class that handles custom exceptions (throw ...) in order to allow a developer to perform try/catch statements in their code when running a query or whatever exchange with SQLite. This works fine except that lastError problem which returns always 1 in case of error. Let's take a short example that performs a faulty query,

<?
$db=new SQLiteDatabase('testdb.db');
if(!$db instanceof SQLiteDatabase) die('Could not instanciate SQLiteDatabase properly');
$db->queryExec('CREATE TABLE a_table(a_column);') or showError(sqlite_error_string($db->lastError()));;
@$db->queryExec('INSERT INTO invalid_table(col) VALUES(\'wrong sql\');') or showError(sqlite_error_string($db->lastError()));
@$db->query('SELECT * FROM invalid_table') or showError(sqlite_error_string($db->lastError()));
/* The errors shown will always be "SQL logic error or missing database" which is normal because $db->lastError always contains "1"*/

function showError($err)
{
echo $err."\n";
}
?>

I noticed the same behaviour with the procedural function sqlite_lasterror

So, is it me or is it PHP ???

Thanks for your help
 
Back
Top