Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

<?php
$db = new SQLiteDatabase("test.db");
unset($db);
$db = sqlite_open("test.db");
sqlite_query($db,"create table students (names char(255))");
sqlite_close($db);
?>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 ....";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...