第 9 行 C:\webdev\wamp\www\membershipSite\classes\Mysql.php 中的用户 'username'@'localhost'(使用密码:YES)访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15208795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access denied for user 'username'@'localhost' (using password: YES) in C:\webdev\wamp\www\membershipSite\classes\Mysql.php on line 9
提问by TheUnCola
I'm new to all of this but I do know a decent amount of HTML/CSS. I want to create a login server and I got most of the code from a video. If someone could help me and explain thoroughly so I can understand it would be greatly appreciated. If any other stuff is needed I will gladly post it.
我对这一切都不熟悉,但我确实知道相当多的 HTML/CSS。我想创建一个登录服务器,并且我从视频中获得了大部分代码。如果有人可以帮助我并彻底解释,以便我理解,将不胜感激。如果需要任何其他东西,我会很乐意发布。
<?php
require_once 'includes/constants.php';
class Mysql {
private $conn;
function _construct() {
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database.');
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
回答by Kevin Seifert
You need to grant permissions to the user@host in mysql. The grant command looks like
您需要向mysql中的user@host授予权限。授予命令看起来像
grant all privileges on YOURDB.* to
'YOURUSER'@'localhost' identified by 'YOURPASSWORD';
回答by OrisHeavens
Just a side answer as i came to this answer from my own problem but had a different solution as i knew all privileges were given to the user in question
只是一个附带的答案,因为我是从我自己的问题中得出这个答案的,但有一个不同的解决方案,因为我知道所有权限都给了有问题的用户
I was using code such as
我正在使用代码,例如
<?php
session_start();
$db_host="host";
$db_user="user";
$db_pass="mypassword";
$db_name="dbname";
$db_table="tblname";
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
The problem here was that the database password that i had used a generator for included a $ symbol which confused the script and thought there was another variable in starting in
这里的问题是我使用生成器生成的数据库密码包含一个 $ 符号,它混淆了脚本并认为在开始时还有另一个变量
$db_pass="mypass$word";