PHP PDO 异常:找不到驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11423677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:29:33  来源:igfitidea点击:

PHP PDO exception: could not find driver

phppdofreebsd

提问by Absolute?ER?

Does the MySQL-server and PHP5-MySQLi version have to match in order for a connection to be possible? I'm currently receiving the error below: I am running BSD. "Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'..."

MySQL-server 和 PHP5-MySQLi 版本是否必须匹配才能进行连接?我目前收到以下错误:我正在运行 BSD。“致命错误:未捕获异常‘PDOException’,消息‘找不到驱动程序’……”

Here is the the connection info:

这是连接信息:

$info = "mysql:dbname=myDB;host=localhost";
$user = "dbUser";
$pw = "somePW";
return(new PDO($info, $user, $pw));

Here is my MySQL information:

这是我的 MySQL 信息:

mysql-server-5.5.24

mysql-server-5.5.24

php5-mysqli-5.4.3

php5-mysqli-5.4.3

采纳答案by John C

PDO uses database specific driversto connect to database systems. It looks like you are missing the pdo_mysql driver that is required to connect to a MySQL database. There is some details on installing the driver on the pdo_mysql manualpage, or there may be a BSD package that you can use (I am afraid I'm not familiar enough with BSD to offer specific advice).

PDO 使用特定于数据库的驱动程序连接到数据库系统。看起来您缺少连接到 MySQL 数据库所需的 pdo_mysql 驱动程序。pdo_mysql 手册页上有关于安装驱动程序的一些详细信息,或者可能有您可以使用的 BSD 包(恐怕我对 BSD 不够熟悉,无法提供具体建议)。

回答by Absolute?ER?

I had this same issue on my CentOS install. I had tried to install imagick and hosed my install. When I removed all of my php files and reinstalled something wasn't working right.

我在安装 CentOS 时遇到了同样的问题。我曾尝试安装 imagick 并冲洗了我的安装。当我删除所有 php 文件并重新安装时,某些东西无法正常工作。

I ran:

我跑了:

yum install php-pdo
yum install php-pdo_mysql

After doing those two lines I ran

做了这两行后,我跑了

service httpd restart

and everything came back up and running.

一切都恢复了运行。

回答by John C

Thanks to zerkms and John C for pointing me in the right direction. Below are the commands I used to install the driver:

感谢 zerkms 和 John C 为我指明了正确的方向。以下是我用来安装驱动程序的命令:

#cd /usr/ports/databases/php5-pdo_mysql
#make install clean
#apachectl restart