[英]I have created a database named 'credentials' having 'userinfo' table in it on wamp server. I am not able to connect the database through php
Error: Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:\\wamp\\www\\form\\update.php on line 8 错误:警告:mysqli :: mysqli():(HY000 / 1045):在第8行的C:\\ wamp \\ www \\ form \\ update.php中,用户'username'@'localhost'的访问被拒绝(使用密码:是)
PHP code: PHP代码:
<?php
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbName = 'credentials';
$link = new mysqli($servername, $username, $password, $dbName);
if (!$link) {
die("Connection Failed: " . mysqli_connect_error());
}
$connect = "INSERT INTO userinfo (username, password) VALUES ('$username', '$password')";
if (mysqli_query($link, $connect)) {
echo "New record created successfully";
}else {
echo "Error: " . $connect . "<br>" . mysql_error($link);
}
mysqli_close($link);
?>
Need to grant permissions to the user@host in mysql. 需要向mysql中的user @ host授予权限。 The grant command looks like
grant命令看起来像
grant all privileges on YOURDB.* to 'YOURUSER'@'localhost' identified by 'YOURPASSWORD';
The value of variables: 变量的值:
$username = 'username';
$password = 'password';
Must be the REAL login information of your database server, something like 'root' or another user, and the password defined during the server setup. 必须是数据库服务器的REAL登录信息,例如“ root”或其他用户,以及服务器设置期间定义的密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.