E / InputlineResult:
警告:mysql_connect():访问 否认用户' root' DESKTOP-2Q0OODR' (使用密码:NO)in 在 28 行 C:\ xampp \ htdocs \ chatter \ mysql.class.php 03-29 22:33:50.633 7032-17538 / com.baidar.androidChatter E / InputlineResult:
警告:mysql_connect():Access 否认用户' root' DESKTOP-2Q0OODR' (使用密码:NO)in 在 28 行 C:\ xampp \ htdocs \ chatter \ mysql.class.php 03-29 22:33:50.633 7032-17538 / com.baidar.androidChatter E / OuterResult:
警告:mysql_connect():拒绝访问 对于用户&root;' DESKTOP-2Q0OODR' (使用密码:NO)in C:\ xampp \ htdocs \ chatter \ mysql.class.php 28 警告:mysql_query()期望参数2成为 资源,布尔值 C:\ xampp \ htdocs \ chatter \ mysql.class.php 在线 68
<?php
class MySQL
{
private $dbLink;
private $dbHost;
private $dbUsername;
private $dbPassword;
private $dbName;
public $queryCount;
function MySQL($dbHost,$dbUsername,$dbPassword,$dbName)
{
$this->dbHost = $dbHost;
$this->dbUsername = $dbUsername;
$this->dbPassword = $dbPassword;
$this->dbName = $dbName;
$this->queryCount = 0;
}
function __destruct()
{
$this->close();
}
//connect to database
private function connect() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);
if (!$this->dbLink) {
$this->ShowError();
return false;
}
else if (!mysql_select_db($this->dbName,$this->dbLink)) {
$this->ShowError();
return false;
}
else {
mysql_query("set names latin5",$this->dbLink);
return true;
}
unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
}
/*****************************
* Method to close connection *
*****************************/
function close()
{
@mysql_close($this->dbLink);
}
/*******************************************
* Checks for MySQL Errors
* If error exists show it and return false
* else return true
*******************************************/
function ShowError()
{
$error = mysql_error();
//echo $error;
}
/****************************
* Method to run SQL queries
****************************/
function query($sql)
{
if (!$this->dbLink)
$this->connect();
if (! $result = mysql_query($sql,$this->dbLink)) {
$this->ShowError();
return false;
}
$this->queryCount++;
return $result;
}
/************************
* Method to fetch values*
*************************/
function fetchObject($result)
{
if (!$Object=mysql_fetch_object($result))
{
$this->ShowError();
return false;
}
else
{
return $Object;
}
}
/*************************
* Method to number of rows
**************************/
function numRows($result)
{
if (false === ($num = mysql_num_rows($result))) {
$this->ShowError();
return -1;
}
return $num;
}
/*******************************
* Method to safely escape strings
*********************************/
function escapeString($string)
{
if (get_magic_quotes_gpc())
{
return $string;
}
else
{
$string = mysql_escape_string($string);
return $string;
}
}
function free($result)
{
if (mysql_free_result($result)) {
$this->ShowError();
return false;
}
return true;
}
function lastInsertId()
{
return mysql_insert_id($this->dbLink);
}
function getUniqueField($sql)
{
$row = mysql_fetch_row($this->query($sql));
return $row[0];
}
function testconnection() {
$this->dbLink = mysql_connect($this->dbHost, $this->dbUsername, $this->dbPassword);
if (!$this->dbLink) {
$this->ShowError();
return false;
}
else if (!mysql_select_db($this->dbName,$this->dbLink)) {
$this->ShowError();
return false;
}
else {
mysql_query("set names latin5",$this->dbLink);
return true;
}
unset ($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
}
}
在第28行,代码显示为Fatal Error
,在第68行显示access denied
。
第28行 - &gt; $ this-&gt; dbLink = mysql_connect($ this-&gt; dbHost,$ this-&gt; dbUsername,$ this-&gt; dbPassword);
线68-> if(!$ result = mysql_query($ sql,$ this-&gt; dbLink))
答案 0 :(得分:1)
错误消息几乎说明了一切。您使用您尝试的凭据无权访问数据库。一个很大的线索是,错误消息告诉您,您尝试在没有密码的情况下访问数据库。
错误在于你已经在名为MySQL
的{{1}}中编写了一个名为class
的函数,它可能是一个构造函数,因为这就是你在这么多中编写构造函数的方法。语言,如Java&amp;合。将其更改为
MySQL
此外,mysql_ 被视为不安全且已弃用。请改用PDO或mysqli_ ,并注意SQL injections。