0

Today some of my packages in Ubuntu was upgraded automatically, and I didn't think of what was actually going on.

Ever since the update, my local dev-environment doesn't work anymore. First of by not working was mod_rewrite which I had to enable again using a2enmod. But now I've run into an issue that I can't seem to resolve. My application can't seem to find the PDO MySQL driver. When running the application, I get the error failed to open the DB connection: could not find driver.

This is strange, since if I check the phpinfo() the PDO drivers do support MySQL, and the socket path is a valid path.

pdo_mysql client API version is 5.5.35 according to php info.

PHP5: 5.5.3 MySQL: 5.5.35

Connectionstring

mysql:host=127.0.0.1;dbname=MyDB;port=3306

What could be causing this?

Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86
  • possible duplicate of [PDOException “could not find driver”](http://stackoverflow.com/questions/2852748/pdoexception-could-not-find-driver) – Tomasz Kowalczyk Mar 25 '14 at 08:54
  • The problem in the "duplicate" was that the module pdo_mysql wasn't enabled. I have that module enabled, and it's showing up in phpinfo. – Anton Gildebrand Mar 25 '14 at 08:57
  • Show us code that you use to connect to DB. Also triple-check that you have `pdo_mysql` module enabled. `php5-mysql` AFAIR is not the package you should be looking at. – Tomasz Kowalczyk Mar 25 '14 at 08:57
  • I am using the Yii framework, where the models uses a class called CDbConnection, which utilizes PDO to connect to the DB defined in my configuration. – Anton Gildebrand Mar 25 '14 at 08:59

2 Answers2

0

The PHP MySQL driver (mysql.so/mysqli.so) and the PHP PDO MySQL driver (pdo_mysql.so) are two separate modules. You need both of them for PDO functionality with MySQL.

It is quite possible that one of them is missing or of an incompatible version - I do not have an Ubuntu system at hand, but on my RPM-based Linux distribution there is a separate package for each module (php-mysql/php-mysqli and php-pdo_mysql). I also expect PDO to be using the newer mysqli.so driver, rather than the obsolete mysql.so one, so you should verify that one is installed as well.

thkala
  • 84,049
  • 23
  • 157
  • 201
-1

Try this:

sudo apt-get install -y php5-mysql php5 mysql-client

This should automatically restart your apache if any of the dependencies aren't installed.

Try using vagrant. Dependencies can be isolated, upgraded and downgraded when you like.

Vagrant

Jens
  • 1,132
  • 7
  • 14