PDO连接MySQL出错
<?php
$dbms = 'mysql';
$dbName = 'db_mrbook';
$user = 'root';
$pwd = '111';
$host = 'localhost';
$dsn = "$dbms:host = $host;dbname = $dbName";
try{
$pdo = new PDO($dsn,$user,$pwd);
echo "PDO链接数据库成功";
}catch(Exception $e){
echo $e->getMessage()."<br>";
}
?>
运行时显示could not find driver
修改了php.ini.dist和php.ini.recommended中的扩展,去掉了extension=php_mysql.dll、extension=php_pdo.dll和extension=php_pdo_mysql.dll前面的分号,重启了Apache,还是同样的错误,请大大帮帮忙阿
------解决方案--------------------phpinfo() 看看是否加载成功
------解决方案--------------------看看phpinfo()中的load configure file ,看看加载的是那个php.ini文件
------解决方案--------------------这样就可以了
PHP code
PDO
PDO support enabled
PDO drivers mysql, odbc, sqlite
pdo_mysql
PDO Driver for MySQL enabled
Client API version mysqlnd 5.0.8-dev - 20102224 - $Revision: 308673 $
PDO_ODBC
PDO Driver for ODBC (Win32) enabled
ODBC Connection Pooling Enabled, strict matching
pdo_sqlite
PDO Driver for SQLite 3.x enabled
SQLite Library 3.7.4
------解决方案--------------------
你改的php.ini 是否是 Loaded Configuration File 对应的php.ini