创建pdo对象时出现Connection failed: could not find driver

WBOY
Release: 2016-06-23 13:40:05
Original
1227 people have browsed it

创建pdo对象的代码:

<?php	try{		$dbh=new PDO("mysql:host=localhost;dbname=name","user","password");	}catch(PDOException $e){		echo 'Connection failed: '.$e->getMessage();	}?>
Copy after login


php.ini配置文件中都已经改成:
extension=php_mysql.dllextension=php_pdo.dllextension=php_pdo_mysql.dll
Copy after login



回复讨论(解决方案)

1、检查 php.ini 是否生效(你修改的文件位置是否正确)
2、php5.3 起已经没有了 php_pdo.dll(pdo 对象已经内置),如果 extension=php_pdo.dll 则会因加载失败而导致 pdo_mysql 失效
3、php5.2 及以前的 pdo 极不稳定,不建议使用

<?phpphpinfo();?>
Copy after login


看看有没有PDO。

使用的是php5.2,看来是由于稳定性的问题造成的,昨晚测试的不可以,今天早上创建成功了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template