无法使用php访问SQLite3数据库

I've spent many-a hour trying to get a local webserver working (I'm new)

I created a sqlite3 database ('database.sql') in the www folder, and tried calling it with numerous different php commands (php 5.5, I checked) such as '$test = new SQLite('database.sql')' or the same with SQLite3, both with no luck. Also tried $test->open('database.sql'). Always with the fatal error "Class 'SQLite' not found". I've spent too many hours on what I'm sure is a very simple problem, I'm sorry to have to ask this!

To open a DB using PHP5 and SQLite we need to use a PDO and not the sqlite_open() function.

This is how to open or create a database: (not sure if it's bug free)

try {
    /*** connect to SQLite database ***/
    $dbh = new PDO("sqlite:VPN0.sqlite");
    echo "Handle has been created ...... <br>";
}

catch(PDOException $e) {
    echo $e->getMessage();
    echo "<br>Database is loaded UNSUCCESSFULLY .. ";
    die("<br>Query is closed $error");
}

echo "Database loaded SUCCESSFULLY ....";

Hope this helps!

Are you sure that the package is installed on your server?

If you're still having problems you can do a couple of things. First, use phpinfo(); in a page to determine if the SQLite3 extension is installed.

Second, if you want to use PDO make sure that the following line in your php.ini is un-commented:

extension=php_pdo_sqlite.dll

If you have to un-comment this you will need to restart your server for the changes to take effect.

There is a php package called sqlite3 which you can use (as well as PDO which is given above). Here is a fraction of code which uses it.

            $db = new SQLite3(DATABASE);
        if (isset($dbversion)) { //only newer versions of chat will have this
            $version = $db->querySingle("SELECT value FROM parameters WHERE name = 'db_version'");

Where the DATABASE variable has been defined with

define('DATA_DIR',$datadir);  //Should be outside of web space
define('DATABASE',DATA_DIR.'chat.db');