Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to connect a sqlite database using PHP?

Tags:

php

sqlite

pdo

i have tried lot to connect database using PHP PDO. i have got lot of samples, i am not sure what was problem.

below is my code

<?php
    try
    {
        // $db = new PDO('sqlite:sampleDB.db3');
        // $db = new SQLiteDatabase('sampleDB.sqlite', 0666, $error);  
        $db = new PDO('sqlite:sampleDB.sqlite');
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
?>

i have tried lot of way to open a connection. please tell me the correct way...

like image 676
ayathas Avatar asked Apr 01 '11 13:04

ayathas


1 Answers

I gave up with PDO driver, and used sqlite3 module instead for same reasons.

With sqlite3 module:

class DB extends SQLite3
{
        function __construct( $file )
        {
            $this->open( $file );
        }
}

$db = new DB( 'sampleDB.sqlite' );

I know it's not a solution for your problem, but if nothing else works, this could be useful.

like image 85
petermolnar Avatar answered Oct 04 '22 12:10

petermolnar