How To Connect A Sqlite Database Using Php?
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
Solution 1:
I gave up with PDO driver, and used sqlite3 module instead for same reasons.
With sqlite3 module:
classDBextendsSQLite3{
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.
Solution 2:
First, you'll want to make sure you've got PHP configured to connect to SQLite - use phpinfo() to check and be sure that you have SQLite support enabled.
Next, you'll want to use the proper syntax when attempting to connect and query against a SQLite database. As per PHP Manual for sqllite e.g.
<?phpif ($db = sqlite_open('sampleDB', 0666, $sqliteerror) ) {
$result = sqlite_query($db, 'select bar from foo');
var_dump(sqlite_fetch_array($result) );
} else {
die($sqliteerror);
}
?>Solution 3:
The directory the sql file is located should be server writable. Try creating separate directory just for SQLite and give it appropriate access. In Unix you can do it so by running chmod 777 dirname. Also, amend your DSN to 'sqlite:dirname/sampleDB.sqlite'.
Post a Comment for "How To Connect A Sqlite Database Using Php?"