我的网站上出现以下错误: 用户“cmoras”@“localhost”的访问被拒绝(使用密码:否)
我不理解如何将'cmoras'作为用户,因为我的config.php文件中没有设置用户名。这是我的config.php文件中的代码:
<?php
/**
* Database config variables
*/
define("DB_HOST", "localhost");
define("DB_USER", "");
define("DB_PASSWORD", "");
define("DB_DATABASE", "TestDB");
/*
* Google API Key
*/
define("GOOGLE_API_KEY", "PgsHJSiKp43460Uvo_AOk_tgXyvIXfhl-z34z89");
define("GOOGLE_API_URL","https://androiddev-1470412665395.firebaseio.com");
define("BASE_URL", "http://www.webiste.com"); //optional
define("PWD", "./");
define("PWP", "https://website.com/api/android/gcm/gcm-server-demo/"); //optional
?>
然后这是处理数据库的文件的代码:
<?php
require_once 'config.php';
class DB_Functions_GCM {
function __construct() {
// connecting to database
$this->mysqlconn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_connect_error());
}
// destructor
function __destruct() {
}
public function connectDefaultDatabase() {
$this->mysqlconn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_connect_error());
return $this->mysqlconn;
}
public function selectDatabase($db) {
mysqli_select_db($this->mysqlconn, $db);
}
public function closeDatabase() {
mysqli_close($this->mysqlconn);
}
public function connectNewDatabase($host, $user, $password, $dbname = "") {
closeDatabase();
if ($dbname != "" && $dbname != null) {
$this->mysqlconn = mysqli_connect($host, $user, $password, $dbname) or die(mysqli_connect_error());
}
else {
$this->mysqlconn = mysqli_connect($host, $user, $password) or die(mysqli_connect_error());
}
return $this->mysqlconn;
}
/**
* Storing new user
* returns user details
*/
/**
* Get user by email and password
*/
public function getUserByEmail($email) {
$result = mysqli_query($this->mysqlconn, "SELECT * FROM gcm_users WHERE email = '$email' LIMIT 1");
return $result;
}
public function getUserByName($username) {
$result = mysqli_query($this->mysqlconn, "SELECT * FROM gcm_users WHERE name = '$username' LIMIT 1");
return $result;
}
public function getUserById($id) {
$result = mysqli_query($this->mysqlconn, "SELECT * FROM gcm_users WHERE id = '$id' LIMIT 1");
return $result;
}
/**
* Getting all users
*/
public function getAllUsers() {
$result = mysqli_query($this->mysqlconn, "select * FROM gcm_users");
return $result;
}
/**
* Check user exists or not
*/
public function checkUserById($id) {
$result = mysqli_query($this->mysqlconn, "SELECT gcm_regid from gcm_users WHERE gcm_regid = '$id'");
$no_of_rows = mysqli_num_rows($result);
if ($no_of_rows > 0) {
return true;
} else {
return false;
}
}
public function deleteUserById($id) {
$result = mysqli_query($this->mysqlconn, "DELETE FROM gcm_users WHERE gcm_regid = '$id'");
if ($result) {
return true;
} else {
return false;
}
}
public function storeUser($gcm_regid, $instanceId, $name, $email) {
echo "$gcm_regid";
// insert user into database
$result = mysqli_query($this->mysqlconn, "INSERT INTO gcm_users(name, email, gcm_instance_id, gcm_regid, created_at) VALUES('$name', '$email', '$instanceId', '$gcm_regid', NOW())");
// check for successful store
if ($result) {
// get user details
$id = mysqli_insert_id($this->mysqlconn);
// last inserted id
$result = mysqli_query($this->mysqlconn, "SELECT * FROM gcm_users WHERE id = $id") or die("Error " . mysqli_error($this->mysqlconn));
// return user details
if (mysqli_num_rows($result) > 0) {
return mysqli_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
}
}
?>
有关导致此问题的任何建议吗?