PDOexception - 'could not find driver'

2019-08-02 09:10发布

问题:

I woork on my local site with MAMP. Everything was going right till yesterday. Now, when I run my code, I get a : "Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'..." It seems that I have non installed driver but it worked well until this day. How can I fix this problem ?

Best, Newben

回答1:

I had a similar problem. Sfblaauw's solution didn't work but it helped me identify the problem. First I installed php5-mysql using MacPorts:

sudo port install php5-mysql

During installation, I got the following warning:

Your php.ini contains a line that will prevent php5-mysql and other PHP extensions from working. To fix this, edit /opt/local/etc/php5/php.ini and delete this line:

extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"

I commented out the line and restarted Apache. Everything seems to work fine now.



回答2:

Have you installed MacPorts? If your answer is "yes" open your Shell and type:

  1. cd ~/
  2. sudo nano .profile
  3. change: export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    replace with: export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.3.6/bin/:$PATH

  4. close your Shell and re-open it

This is all. I found the solution here: thewebfactory



标签: macos pdo mamp php