Fatal error: Uncaught PDOException: could not find driver

I'm having an issue where the PHP interpreter is working as expected when I'm running from the command line, but if I open a PHP page through PHPStorm, I'm getting a different result.

I have a very simple program to test that I'm connecting to the DB as I expect:

When running from the command line, I'm getting the result I expect: PDO is created (Connected to the DB):

However, when I open this page in a browser, the PDO isn't created, and the exception is thrown:

This is problematic because in the code I'm working on, it's looking for a driver in an odd location:

I made sure my PHP instance has pdp_mysql enabled in php.ini

extension=pdo_mysql
 
And PDO and MySQL are being properly loaded:
 
 
Is there something I needed to do in PHPStorm to make it aware of the PDO library?
 
The one thing that is odd is that if I do a phpinfo(), the PDO section seems to be blank:
 
2 comments
Comment actions Permalink

I solved this problem but have no idea why.

It may be that even though I was turning Apache on and off, PHPStorm held an active connection to it. I restarted PHPStorm and now my PD values are populated:

I have no explanation for this.

0
Comment actions Permalink

Hi there,

It may be that even though I was turning Apache on and off, PHPStorm held an active connection to it.

Nope.

The URL used  (localhost:63342) tells that you were using PhpStorm's built-in simple web server. https://www.jetbrains.com/help/phpstorm/php-built-in-web-server.html

I restarted PHPStorm and now my PD values are populated:

The built-in webserver was restarted with PhpStorm. After the restart it read the new php.ini with your changes.

 

P.S. If you wish to use your local Apache (XAMPP/WAMP/vanilla Apache or whatever you may have there) then please set up the Deployment entry (In-place type can do the job, depends on your actual setup), specify the URL to be used and make sure that this entry is marked as Default for this project.

When there is no default deployment then built-in webserver URL is used.

0

Please sign in to leave a comment.