PHP Fatal error: Uncaught Error: Class 'Sqlite3' not found in /var/www/html/

Asked

Viewed 1,720 times

0

I have the code below supposedly simple. The intuition is to create a table include values and soon after showing the information, but in the log apache is showing the following:

[:error] [pid 17622] [client 10.1.21.1:42895] PHP Fatal error:  Uncaught Error: Class 'SQLite3' not found in /var/www/html/acesso.php:2\nStack trace:\n#0 {main}\n  thrown in /var/www/html/acesso.php on line 2
<?php   
  $db = new SQLite3('test.db');

  $db->exec('CREATE TABLE test (id INT, message STRING)');

  $db->exec("INSERT INTO test (id, message) VALUES ('1', 'test message')");
  $db->exec("INSERT INTO test (id, message) VALUES ('2', 'test message 2')");

  $results = $db->query("SELECT * FROM test WHERE ID = 2");

  print_r($results->fetchArray());

?>

PHP Summer : 7.0

OS Version : Ubuntu 16.10

Sqlite version installed: 3.14.1

Apache Version: Apache/2.4.18 (Ubuntu)

  • Give phpinfo() and see if sqlite mode is installed

  • After using phpinfo() and confirming that the extension for Sqlite is not enabled just remove the comment "Extension=php_pdo_sqlite.dll" in php.ini and restart apache

  • uncommented, restarted service and error continues.

  • 1

    You’ll have to restart your server, since PHP may have been installed as a server environment variable, not just Apache/IIS

2 answers

2


You have activated the sqlite3 module in Ubuntu PHP7?

To activate, just go to the server and type in the console:

sudo apt-get update
sudo apt-get install php7.0-sqlite3

See if it solves, if it doesn’t check the Apache modules, in Ubuntu it has the command a2enmod you can use to activate modules.

  • 1

    it is quite likely that it is even lack of turning the a2enmod ;)

  • In my case it was also necessary to re-load the apache settings. /etc/init. d/apache2 Reload

0

There you go, you can’t find the Sqlite3 class. You can use include_once(file_da_class)to test

  • Problem solved with class instance a still had directory permission I needed to change

Browser other questions tagged

You are not signed in. Login or sign up in order to post.