更新时间:2023-12-01 21:14:40
该用户没有权限数据库或密码错误。
否则,删除用户并使用以下语句创建:
1。创建用户'user'@'localhost'由'123456789'标识;
2.
3.授予项目上的所有特权。*授予用户 @本地主机的权限;
或尝试以下操作:
<?php
$ servername = localhost;
$ username =用户名;
$ password =密码;
$ dbname = dbname;
//创建
$ conn =新的mysqli($ servername,$ username,$ password,$ dbname);
//检查
是否($ conn-> connect_error){
die(连接失败:。$ conn-> connect_error);
}
echo Yaaay;
?>
I am trying to connect to mysql on server but gives following error. User is created and granted all privileges.
Its working on local machine but not after deploying to server.
Also mysql_connect
function works but new mysqli()
gives access denied as mentioned below.
Also Tried adding port.
Warning: mysqli::mysqli(): (HY000/1045): Access denied for user ''usernam'@'localhost' (using password: YES) in /home/domainname/public_html/autopublish/test.php on line 8 Connection failed: Access denied for user ''username'@'localhost' (using password: YES)
<?php
$servername = "localhost";
$username = "'xxxxx";
$password = "xxxxx";
$dbname = "xxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password); **//line 8**
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "no connection";
}
$sql = "SELECT * FROM pages";
$result = $conn->query($sql);
$data = array();
$arr = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
}
} else {
echo "No Token";
}
print_r(json_encode($data));
$conn->close();
?>
Either the user does not have the required rights for the database or the password is wrong.
Otherwise remove the user and use the following statement to create:
1.CREATE USER 'user'@'localhost' IDENTIFIED BY '123456789';
2.
3.GRANT ALL PRIVILEGES ON project.* TO 'user'@'localhost' WITH GRANT OPTION;
or try this:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
//Create
$conn = new mysqli($servername, $username, $password, $dbname);
//Check
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Yaaay";
?>