Results 1 to 9 of 9

Thread: Fatal error: Class 'SQLite3' not found in....

  1. #1
    Join Date
    Jan 2007
    Beans
    97
    Distro
    Ubuntu 10.04 Lucid Lynx

    Fatal error: Class 'SQLite3' not found in....

    Running 8.04 64bit desktop w/LAMP added and would like to try out SQLite3 with PHP.

    I get the error when running the example from:
    http://us.php.net/manual/en/sqlite3.open.php

    as follows:

    root@voyager:/var/www/foliofn# cat example.php; php example.php
    <?php
    $db = new SQLite3('mysqlitedb.db');

    $db->exec('CREATE TABLE foo (bar STRING)');
    $db->exec("INSERT INTO foo (bar) VALUES ('This is a test')");

    $result = $db->query('SELECT bar FROM foo');
    var_dump($result->fetchArray());
    ?>

    Fatal error: Class 'SQLite3' not found in /var/www/foliofn/example.php on line 2
    root@voyager:/var/www/foliofn#

    I have used synaptic to install anything I could find related to SQLite/SQLite3.

    Any Ideas?

    John

  2. #2
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Fatal error: Class 'SQLite3' not found in....

    Same here. I have SQLITE3 extension enabled with version 3.4.2 and yet this doesnt work !
    I did sudo apt-get install php5-sqlite php5-slite3

  3. #3
    Join Date
    Aug 2008
    Location
    Australia
    Beans
    6
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Fatal error: Class 'SQLite3' not found in....

    Likewise here. I've installed all the php-sqlite packages and accessories for it (yes, and php5-sqlite3 etc) to no avail (restarted apache).

    Hope there's a fix for this

  4. #4
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Fatal error: Class 'SQLite3' not found in....

    The installation section http://php.net/manual/en/sqlite3.installation.php doesnt have anything in it !
    Is this still in development ?

  5. #5
    Join Date
    Jan 2008
    Beans
    6

    Re: Fatal error: Class 'SQLite3' not found in....

    These instructions should get the SQLite3 class installed.

    Code:
    $ sudo apt-get install php5-cli php5-dev make
    $ sudo apt-get install libsqlite3-0 libsqlite3-dev
    $ sudo apt-get install php5-sqlite3
    $ sudo apt-get remove php5-sqlite3
    $ cd ~
    $ wget http://pecl.php.net/get/sqlite3-0.6.tgz
    $ tar -zxf sqlite3-0.6.tgz
    $ cd sqlite3-0.6/
    $ sudo phpize
    $ sudo ./configure
    $ sudo make
    $ sudo make install
    $ sudo apache2ctl restart
    Thanks again Anthony.
    Last edited by wsams; February 23rd, 2009 at 05:34 PM. Reason: Incomplete instructions.

  6. #6
    Join Date
    Oct 2008
    Beans
    9

    Re: Fatal error: Class 'SQLite3' not found in....

    Note that this doesn't actually get PHP to load the extension, so once you've compiled the SQLite3 extension as shown above:

    Code:
    cd /etc/php5/conf.d
    sudo nano sqlite3.ini
    ...and insert this into the file:

    Code:
    # configuration for php SQLite3 module
    extension=sqlite3.so
    Save and then restart Apache:

    Code:
    sudo /etc/init.d/apache2 restart
    And the SQLite3 class should be available in PHP.

    By the way, currently there is no installation candidate for php5-sqlite3 in Jaunty, so don't worry if the install complains about that; just continue on, since you're compiling it from source anyway.

  7. #7
    Join Date
    Jan 2007
    Beans
    97
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Fatal error: Class 'SQLite3' not found in....

    Thanks wsams and Spoom;

    John

  8. #8
    Join Date
    Nov 2009
    Beans
    2

    Re: Fatal error: Class 'SQLite3' not found in....

    Apparently a change of method to PDO, see comment by user pomax in http://www.php.net/manual/en/intro.sqlite3.php

    The PDO (PHP Data Object) is documented here - http://www.php.net/manual/en/book.pdo.php

    I successfully used:

    <?php

    /* create new database (OO interface) */
    $db2 = new PDO('sqlite:/my_folder/db_php.sqlite');
    /* $db2 = new SQLite3("/my_folder/db_php.sqlite"); */
    /* create table foo and insert sample data */
    $db2->exec("BEGIN;
    CREATE TABLE foo (name);
    INSERT INTO foo (name) VALUES('Ilia');
    INSERT INTO foo (name) VALUES('Ilia2');
    INSERT INTO foo (name) VALUES('Ilia3');
    COMMIT;");
    /* execute a query */

    $sql = "SELECT name FROM foo";
    foreach ($db2->query($sql) as $row) {
    print $row['name'] . "\t";

    }
    /* not generally needed as PHP will destroy the connection */
    $db2 = null;

    ?>

    PS When I tried the sqlite_open, I got a Sqlite 2 file

  9. #9
    Join Date
    Apr 2008
    Location
    Montréal
    Beans
    10
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Fatal error: Class 'SQLite3' not found in....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •