PDOException“找不到驱动程序" [英] PDOException “could not find driver”

查看:124
本文介绍了PDOException“找不到驱动程序"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚用Apache,MySQL和PHP安装了Debian Lenny,并且收到PDOException could not find driver.

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_HOSTDB_NAMEDB_USERDB_PASS是我定义的常量.在生产服务器(以及我以前的Ubuntu Server设置)上,它运行良好.

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
  • PHP5: sudo apt-get install php5-mysql
  • PHP7: sudo apt-get install php7.0-mysql

最后,要使其正常运行,您将需要重新启动Web服务器:

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
  • Apache: sudo /etc/init.d/apache2 restart
  • Nginx: sudo /etc/init.d/nginx restart

这篇关于PDOException“找不到驱动程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆