PDOException“找不到驱动程序" [英] PDOException “could not find driver”
问题描述
我刚刚安装了带有 Apache、MySQL 和 PHP 的 Debian Lenny,但收到 PDOException 找不到驱动程序
.
I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver
.
这是它所指的特定代码行:
This is the specific line of code it is referring to:
$dbh = new PDO('mysql:host=' .DB_HOST .';dbname='.DB_NAME, DB_USER, DB_PASS)
DB_HOST
、DB_NAME
、DB_USER
和 DB_PASS
是我定义的常量.它在生产服务器(以及我之前的 Ubuntu 服务器设置)上运行良好.
DB_HOST
, DB_NAME
, DB_USER
, and DB_PASS
are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).
这与我的 PHP 安装有关吗?
Is this something to do with my PHP installation?
在互联网上搜索没有帮助,我得到的只是专家交流和示例,但没有解决方案.
Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.
推荐答案
您代码中的 dsn 表明您正在尝试连接 mysql 驱动程序.您的错误消息表明此驱动程序不可用.
The dsn in your code reveals you are trying to connect with the mysql driver. Your error message indicates that this driver is unavailable.
检查您的服务器上是否安装了 mysql 扩展.
Check that you have the mysql extension installed on your server.
在 Ubuntu/Debian 中,您可以使用以下命令检查软件包:
In Ubuntu/Debian you check for the package with:
dpkg --get-selections | grep php | grep mysql
如果没有安装php5-mysql包.
Install the php5-mysql package if you do not have it.
在 Ubuntu/Debian 中你可以使用:
In Ubuntu/Debian you can use:
- PHP5:
sudo apt-get install php5-mysql
- PHP7:
sudo apt-get install php7.0-mysql
最后,要使其正常工作,您需要重新启动您的网络服务器:
Lastly, to get it working, you will need to restart your web-server:
- Apache:
sudo/etc/init.d/apache2 restart
- Nginx:
sudo/etc/init.d/nginx restart
这篇关于PDOException“找不到驱动程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!