我可以设置MySQL PDO驱动程序
我正在尝试将PHP连接到我的MySQL数据库,但是我已经找到了“找不到驱动程序”消息。 我正在使用Windows工作,并且使用PHP -S Localhost:9000
这是我用来连接数据库的代码:
$servername = "localhost";
$port = "3306";
$username = "root";
$password = "password";
$dbname = "mydb";
$dsn = "mysql:host=" . $servername . ";port=" . $port . ";dbname=" . $dbname;
try {
$pdo = new PDO($dsn, $username, $password);
$retour["connected"] = true;
$retour["message"] = "Connexion à la base de données réussie";
// set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
$retour["connected"] = false;
$retour["message"] = "Erreur lors de la tentative de connexion";
} ?>
为确保,$ dbname应该是我的MySQL模式的名称,对吗?
关于缺失的驱动程序,我尝试了这些事情:
- uuncomment extension_dir =“ ext”在我的php.ini中的两行上。
- 相同的扩展名= PDO_MYSQL。
- PHP -V给了我与我使用的版本相同的版本。
- phpinfo()为我提供了一个“配置文件(php.ini)路径=>”
- 我尝试在c:/windows上复制我的php.ini
。事先感谢您的帮助!
I'm trying to connect php to my MySQL databse, but I've a "could not find driver" message.
I'm working on Windows and I use php -s localhost:9000
This is the code I'm using to connect my database :
$servername = "localhost";
$port = "3306";
$username = "root";
$password = "password";
$dbname = "mydb";
$dsn = "mysql:host=" . $servername . ";port=" . $port . ";dbname=" . $dbname;
try {
$pdo = new PDO($dsn, $username, $password);
$retour["connected"] = true;
$retour["message"] = "Connexion à la base de données réussie";
// set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
$retour["connected"] = false;
$retour["message"] = "Erreur lors de la tentative de connexion";
} ?>
Just to be sure, $dbname should be my MySQL schema's name, right ?
About the missing driver, I've tried to those things:
- Uuncomment extension_dir="ext" on both lines in my php.ini.
- Same for extension=pdo_mysql.
- php -v is giving me the same version I'm using.
- phpinfo() is giving me a "Configuration File (php.ini) Path => "
- I've tried to copy my php.ini at C:/Windows
I'm out of ideas. Thanks in advance for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)