我可以设置MySQL PDO驱动程序

发布于 2025-02-06 02:52:22 字数 1037 浏览 2 评论 0原文

我正在尝试将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玉环 2025-02-13 02:52:22

在您的浏览器中,使用Localhost:3306或Localhost代替Local主机:9000。

In your browser, use localhost:3306 or localhost instead of localhost:9000.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文