我刚刚安装了Debian Lenny与Apache, MySQL和PHP,我收到一个PDOException无法找到驱动程序。

这是它所引用的特定代码行:

$dbh = new PDO('mysql:host=')。DB_HOST。”;dbname = '。Db_name, db_user, db_pass)

DB_HOST、DB_NAME、DB_USER和DB_PASS是我已经定义的常量。它在生产服务器(以及我之前的Ubuntu server设置)上运行良好。

这与我的PHP安装有关吗?

在网上搜索也没有帮助,我得到的都是专家交流和例子,但没有解决方案。


当前回答

问题是一个丢失的php到mysql库。在CentOs中,我通过运行来修复它 # yum install php-mysql,然后用# /bin/systemctl restart httpd重启apache。注意,命名与基于debian/ubuntu的发行版,php->php5和httpd->apache2略有不同。

其他回答

对于那些使用Symfony2/3并想知道为什么会得到这个错误的人。如果您正在使用“mapping_types”,则可能会遇到此错误。原因是“mapping_types”被放在了错误的级别。例如:

doctrine:
  dbal:
    mapping_types:
        set: string

这个“mapping_types”必须放在这个级别:

doctrine:
dbal:
    #To counter the error caused by 'mapping_types'
    connections:
        default:
            server_version: %database_server_version%
            mapping_types:
                set: string

我希望这对你们有帮助

我在这里找到了解决方案:https://github.com/doctrine/DoctrineBundle/issues/327

对于有PHP 7.0的新版本的Ubuntu,你可以得到PHP -mysql包:

sudo apt-get install php-mysql

然后重新启动服务器:

sudo service apache2 restart

Linux Mint

我在使用PhpBrew(5.5.9 / 7.0.14)并试图创建PDO连接时遇到了同样的问题。

在我尝试了这篇文章中的大部分解决方案后,我做了以下事情:

关闭PhpBrew 执行sudo apt-get install php7.0 (Linux Mint 17.2 / PHP7.0.16) -安装新的php版本

在我的情况下(Windows XP + Apache2.2 + PHP 5.4.31),我改变了PHPIniDir在httpd.conf来解决这个问题:

来自:

"C:\php5\" 

to:

"C:/php5/"

我通过启用php_pdo_mysql解决了这个问题。“IIS信息服务- > PHP扩展”中的ddl。