Bivis Bivis - 11 months ago 105
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
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
    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 in folder

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


Configurations files below:


; configuration for php SQLite module
; priority=20


; configuration for php SQLite module
; priority=20


Find this error on apache error.log

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/' - /usr/lib/php5/20121212/ 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 Source

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.