Hi, I used PHP to create a database with a table. I did it in the following way:

$db = new SQLiteDatabase("test.db");
$db = sqlite_open("test.db");
sqlite_query($db,"create table students (names char(255))");

After I execute my PHP file from the command line: "php test.php" I get a new file in my directory which is called "test.db" (this is what I wanted). Than, in the command line, I type "sqlite3 test.db". In this way I enter in the sqlite command line session. Then, withing sqlite3, I type ".tables" (I wanted to check if a new database contains tables which it is supposed to contain). As the result I get:

Error: file is encrypted or is not a database

So, it does not work. Does anybody know something about this problem? Thank you in advance for any help.

+1  A: 

this is most likely an version mismatch between the php sqlite version and your standalone sqlite executable.

see this: - under "user contributed notes", from Andrew Paul Dickey.

for a quick solution you can install and use the sqlite2 standalone executable.


Why do you open the db two times ?

Try this code:

$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().