Bivis Bivis - 24 days ago 10
PHP Question

PHP returning PDOException 'could not find driver' when trying to connect do SQLite3

I'm trying to connect a SQLite Database using PDO, but i am getting this error:


Uncaught exception 'PDOException' with message 'could not find driver'


In my code:

$db = new PDO('sqlite:remedios.sqlite');


Also, the command
PDO::getAvailableDrivers()
lists only mysql.
I am using a Ubuntu 14.04

But the problem is that I already installed pdo_sqlite (installed with
apt-get sqlite3 php5-sqlite
).
I also checked it on:


  • My phpinfo() shows sqlite3 (phpinfo is here: PHPInfo)

  • I have
    extension=pdo_sqlite.so
    in my PHP configuration file in /etc/php5/apache2/conf.d/20-pdo_sqlite.ini (phpinfo lists this file in "Additional .ini files parsed")

  • I have pdo_sqlite.so in folder
    /usr/lib/php5/20121212

  • Already tried to reinstall sqlite3, php5, php5-sqlite



Edit



Configurations files below:

20-pdo_sqlite.ini

; configuration for php SQLite module
; priority=20
extension=pdo_sqlite.so


20-sqlite3.ini

; configuration for php SQLite module
; priority=20
extension=sqlite3.so


Edit2



Find this error on apache error.log

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/pdo_sqlite.so' - /usr/lib/php5/20121212/pdo_sqlite.so: undefined symbol: sqlite3_column_table_name in Unknown on line 0
[Fri Nov 13 00:03:42.704671 2015] [mpm_prefork:notice] [pid 1938] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.14 OpenSSL/1.0.1f configured -- resuming normal operations
[Fri Nov 13 00:03:42.704702 2015] [core:notice] [pid 1938] AH00094: Command line: '/usr/sbin/apache2'

Answer

You are missing the SQLite client library, I think the package is libsqlite3-0 on Ubuntu:

apt-get install libsqlite3-0

restart Apache after that.

UPDATE - we figured it out in the chat with the help of ldconfig -p | grep sqlite. It found a stale installation of libsqlite3 in /usr/local/lib that was conflicting with the one that Apache was using. Removing the conflicting installation, and re-installing sqlite3 packages solved the problem.