简体   繁体   English

在本地主机 XAMPP 上连接的这个 PHP 代码有什么问题

[英]What is the issue in this PHP code to connect on localhost XAMPP

The error is: Connection failed: SQLSTATE[HY000] [1045] Access denied for user 'moomen'@'localhost' (using password: YES)错误是:连接失败:SQLSTATE[HY000] [1045] 用户 'moomen'@'localhost' 的访问被拒绝(使用密码:是)

Code is:代码是:

<?php
$servername = "localhost";
$username = "moomen";
$password = "9124279123";
$dbname = "ecocaa";
try {
$conn = new PDO("mysql:host=$servername;dbname=$servername", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";

} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}

I can see a problem in your code In the dbname you have used server name, change the code it will work.我可以在您的代码中看到一个问题在您使用服务器名称的 dbname 中,更改它将起作用的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM