2

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!

1
  • make a list of all the commands you tried and what happened. It would help the answerers. Commented Jun 11, 2014 at 17:01

3 Answers 3

2

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!

Sign up to request clarification or add additional context in comments.

2 Comments

"loaded UNSUCCESSFULLY", says "Could not find driver" and "Undefined Variable"
@user3730954 You need to install the PDO (php data object). Here is the link: php.net/manual/en/pdo.installation.php
2

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');

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.