I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver
.
This is the specific line of code it is referring to:
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)
DB_HOST
, DB_NAME
, DB_USER
, and DB_PASS
are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).
Is this something to do with my PHP installation?
Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.
Everywhere I go I read that the path of
extension_dir
should be changed fromext
to an absolute path. It worked for me. However, when trying to build a server of my colleague's PC, I had to let the value toext
instead of putting an absolute path.If you did put an absolute path and it does the extension is still not found, considerer trying both with the absolute path and
ext
.For Linux Mint
I had the same issue whilst using PhpBrew ( 5.5.9 / 7.0.14 ) and trying to create a PDO connection.
After I had tried most of the solutions on this post I did the following:
Powered off PhpBrew
Executed
sudo apt-get install php7.0
(Linux Mint 17.2 / PHP7.0.16) - installed fresh php versionI had the same exception when trying to use
pdo_sqlite
. The problem was that the automatically created20-pdo_sqlite.ini
and20-sqlite3.ini
symlinks (in/etc/php5/mods-enabled
) were broken.Removeing the broken symlinks and adding them manually with:
sudo ln -s /etc/php5/mods-avaliable/pdo_sqlite.ini /etc/php5/mods-enabled/20-pdo_sqlite.ini
sudo ln -s /etc/php5/mods-avaliable/sqlite3.ini /etc/php5/mods-enabled/20-sqlite3.ini
fixed the problem.
On Ubuntu just execute
I Fixed this issue on my Debian 6. Normally I just had installed
php5-common
package. After installation, you have to restart your web server (apache or nginx depending on which one you installed). Then I just do anlsof
on the apache process id (lsof -p process_id
) as followed :As you can see above, the modules are installed on a file path not known or guided by common library path: /
usr/lib/php5/20090626/
. For your installation, it may be different, but only the path of pdo_mysql.so, pdo.so, mysqli.so. So, this is why Drupal or any other php engine couldn't find the library and shows that error:PDOException: could not find driver
I just don't know why it is installed on such a weird path, for me it's just a bug in the library package installation script in debian 6. I solved the issue by creating a symbolic for all the files under
/usr/lib/php5/20090626/
to/usr/lib/php5/
with this command :ln -s /usr/lib/php5/20090626/* /usr/lib/php5/
If you read all answer above and it still does not work...
Make sure that your PHP PDO connection string is fine. Not like mine:
$dbh = new PDO('"mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)
There is no information in error message what driver was not found.
After reinstalling all possible PDO and MySQL libraries I found out that there was " at start of my connection string.