I used PHP to create a database with a table. I did it in the following way:
this is most likely an version mismatch between the php sqlite version and your standalone sqlite executable.
see this: http://us3.php.net/manual/en/book.sqlite.php - under "user contributed notes", from Andrew Paul Dickey.
for a quick solution you can install and use the sqlite2 standalone executable.
The question is two years old but now it can be solved this way:
class MyDB extends SQLite3
{
function __construct()
{
$dbFile = __DIR__ . '/../../../adminer/Dictionary.sqlite';
$this->open($dbFile);
}
}
$db = new MyDB();
$db->exec('CREATE TABLE students (names VARCHAR(80))');
echo "done";
Source: http://php.net/manual/en/sqlite3.open.php
This is a version mismatch issue.
To open a database using PHP5 and SQLite we need to use a PDO and not the sqlite_open()
function. An example of how to open or create a database:
try
{
/*** connect to SQLite database ***/
$dbh = new PDO("sqlite:VPN0.sqlite");
echo "Handle has been created ...... <br><br>";
}
catch(PDOException $e)
{
echo $e->getMessage();
echo "<br><br>Database -- NOT -- loaded successfully .. ";
die( "<br><br>Query Closed !!! $error");
}
echo "Database loaded successfully ....";
There's one more simple way to solve that problem. You can convert sqlite 2 database file to sqlite 3. I did that with SQLiteManager program on Mac OS X.
I recently encountered this exact same problem and have figured out what is going on. (Yes all the other answers are correct - it is a version mismatch problem.) A am posting this to provide some additional information that may be helpful to others encountering this problem...
The error is due to the fact that the sqlite3.exe
command line tool (which implements SQLite version 3), cannot read database files created using PHP's procedural interface to SQLite (which implements SQlite version 2).
I am following a tutorial which describes how to use SQLITE with PHP: SQLite PHP tutorial (Note that I am running PHP 5.2.14 on Windows XP). As it turns out PHP 5.2 has two (incompatible) ways of interfacing with the SQLite database management system; a procedural API (SQLite) and an object oriented API (SQLite Functions (PDO_SQLITE)). The procedural API uses SQLite version 2 and the OOP API uses SQLite version 3. For Windows PHP platforms, the procedural API is enabled by uncommenting this line in php.ini
:
extension=php_sqlite.dll
While the OOP API is enabled by uncommenting these lines:
extension=php_pdo.dll
extension=php_pdo_sqlite.dll
Note that there is a free Win32 tool that allows administration and manipulation of any version of SQLite databases: SQLite Administrator. This tool allows one to convert a version 2 database (created with the procedural API of PHP) into a version 3 database that can be read using the sqlite3.exe
command line tool.
Why do you open the db two times ?
Try this code:
<?php
$db = sqlite_open( "test.db", 066, $err );
sqlite_query( $db, "CREATE TABLE students (names VARCHAR(80))" );
sqlite_close( $db );
?>
Edit: Fin is probably right; maybe you have to check the SQLite version with phpinfo().