PDO:找不到驱动程序 php/mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14798262/
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
PDO: Could not find driver php/mysql
提问by John Cody
i'm having issues connecting to my database on a web host that I have, i'm using the following:
我在连接到我拥有的网络主机上的数据库时遇到问题,我正在使用以下内容:
$dsn = 'mysql:host=mysql1.hosting.digiweb.ie;dbname=mydbname';
$user = 'myusername';
$password = 'mypassword';
According to the website: Host Name mysql1.hosting.digiweb.ie (ip address)
根据网站:Host Name mysql1.hosting.digiweb.ie(ip地址)
as the title says i'm getting a could not find driver error, am i entering the host incorrectly i tried entering whats above and also the ip address - Thanks!
正如标题所说,我遇到了找不到驱动程序的错误,我是否错误地输入了主机,我尝试输入上面的内容以及 IP 地址 - 谢谢!
Edit:
编辑:
Here's all my code
这是我所有的代码
<?php
$dsn = 'mysql:host=localhost;dbname=';
$user = '';
$password = '';
try {
// Connect and create the PDO object
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo 'Database connection failed - ';
echo $e->getMessage();
exit;
}
echo 'works';
?>
回答by echo_Me
go to your php.ini file and uncomment this line
转到您的 php.ini 文件并取消注释此行
extension=php_pdo_mysql.dll
and then restart your apache
然后重启你的 apache
回答by Failo
Change your extension dir to be absolute in php.ini. I changed it from
在 php.ini 中将您的扩展目录更改为绝对目录。我把它从
extension_dir = "ext"
to
到
extension_dir = "C:/{PATH TO PHP DIRECTORY}/ext"
and it worked.
它奏效了。

