Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure SQLite3 for PHP 5.6.14 on Apache 2.4 (Windows 7)?

I'm on Windows 7, using PHP Version 5.6.14 on Apache 2.4 and I'm trying to access to a SQLite3 database.

I'm obtaining ....

Fatal error: Class 'SQLite3' not found

Here you're a simple php code ...

<?php
  $db = new SQLite3('phpdb');

  if ($db) {
    $db->query("CREATE TABLE dogbreeds (Name VARCHAR(255), MaxAge INT);");
    $db->query("INSERT INTO dogbreeds VALUES ('Doberman', 15)");
    $result = $db->query("SELECT Name FROM dogbreeds");
    var_dump($result->fetchArray(SQLITE3_ASSOC));
  } else {
    print "Connection to database failed!\n";
  }
?>

I've just looking for information about and based on this at the moment I've this configuration in my php.ini file ...

extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
sqlite3.extension_dir = "D:\Cesare\Lavoro\Utili\Php\5-6-14\ext"

Any suggestions? Thank you very much in advance ....

Cesare

like image 281
Cesare Avatar asked Nov 26 '15 13:11

Cesare


2 Answers

Enable extension php by removing the ";" in front of ";extension=php_sqlite3.dll" in php.ini. Can you also manually check if the extensions are there in the path?

`extension=php_pdo_sqlite.dll` AND `extension=php_sqlite3.dll`. 

Try this

$db = sqlite_open("/absolute/path/my_sqlite.db");

or

 $db = new SQLiteDatabase('filename')) 

http://php.net/manual/en/book.sqlite.php

like image 72
Gary Avatar answered Nov 11 '22 04:11

Gary


I met the same problem, I solved it by changing the "extension_dir" using the absolute path

extension_dir = "C:/php/php7.0/ext"

the others setting

extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
sqlite3.extension_dir = "C:/php/php7.0/ext"
like image 2
job wang Avatar answered Nov 11 '22 04:11

job wang