Windows 中的 PHP 5.5.21/Apache 2.4/MySQL 5.6.22 出现 PHP PDO "could not find driver"错误

标签 php mysql windows pdo

我有一个带有 PDO 的简单 .php 文件

<?php
// DB connection info
$host = "localhost";
$user = "root";
$pwd = "1234";
$db = "registration";
try{
    $conn = new PDO( "mysql:host=$host;dbname=$db", $user, $pwd);
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    $sql = "CREATE TABLE registration_tbl(
                id INT NOT NULL AUTO_INCREMENT,
                PRIMARY KEY(id),
                name VARCHAR(30),
                email VARCHAR(30),
                date DATE)";
    $conn->query($sql);
}
catch(Exception $e){
    die(print_r($e));
}
echo "<h3>Table created.</h3>";
?>

当我执行这个 php 文件时,我可以看到这个错误消息。

PDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\Apache24\htdocs\registration\createtable.php [line:protected] => 8 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\Apache24\htdocs\registration\createtable.php [line] => 8 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhost;dbname=registration [1] => root [2] => 1234 ) ) ) [previous:Exception:private] => [errorInfo] => ) 1

所以我取消注释并根据其他关于类似问题的问题和答案设置'php.ini'文件。

extension=php_pdo_mysql.dll
extension_dir = "c:/php/ext" (absolute Path)

但是,情况并没有特别的变化。仍然找不到驱动程序。

但是,当我输入“php -m”和“php -i”时,我发现 PDO 已启用。

php -m

[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
ereg
filter
ftp
hash
iconv
json
libxml
mcrypt
mhash
mysqlnd
odbc
pcre
PDO
pdo_mysql
Phar
Reflection
session
SimpleXML
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

php -i

pcre.backtrack_limit => 1000000 => 1000000
pcre.recursion_limit => 100000 => 100000

PDO

PDO support => enabled
PDO drivers => mysql

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb10
57292d73b928b8c5c77 $

Phar

Phar: PHP Archive support => enabled
Phar EXT version => 2.0.2
Phar API version => 1.1.1
SVN revision => $Id: cc0fad28eb9ea42466f756c3b5fc22c764e32690 $
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => disabled (install pecl/bz2)
OpenSSL support => disabled (install ext/openssl)

为什么他们找不到 PDO 驱动程序?请帮我。谢谢你。

最佳答案

对我来说,我发现扩展名(extension=php_pdo_mysql.dll) 在php.ini 中被注释掉了。

删除了';'从线路开始,重新启动服务和 XAMPP,一切都很好。

关于Windows 中的 PHP 5.5.21/Apache 2.4/MySQL 5.6.22 出现 PHP PDO "could not find driver"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28121852/

相关文章:

php - 如何检查用户是否有权限查看文档

windows - 批处理文件输入验证 - 确保用户输入了一个整数

PHP 中的 Javascript 蓝调 : getElementById & getElementsByClassName

PHP:setcookie() 和 unset() 不删除 cookie

php - 我的 session 变量是如何在远程页面上定义的?只是对背景知识感到好奇

php - 如何为命令行 PHP 脚本触发 XDebug 探查器?

c# - 如何从 MySQL 数据库内容动态创建 Access DB 并保存在本地

mysql - 根据时间戳计算出总秒数

python - 如何从 Windows 注册表中删除多个版本的 Python

c++ - SendMessage(hwnd, registeredmssghere, 0, 1) 收到但未被发送到的 Hook 线程正确识别!