Posted over 8 years ago
PHP could not find driver
I ran into an issue today where I could not connect to a database. Googling led me down the wrong path. The actual solution turned out to be pretty simple.
When attempting a connection I would get the following exception:
could not find driver
Googling the error produced quite a few results. Most of which were related to pdo_mysql not being installed or configured correctly.
It turned out that the actual problem was that I neglected to include ‘mysql://’ in the DSN string.
I’m not sure what driver PHP looks for when a database identifier is not specified. I would have expected/preferred an exception like “Database type not specified,” or something along those lines.
In summary, all I needed to do was to prefix my DSN string with the ‘mysql://’ to get things working.