警告:mysql_query():访问被拒绝用户'admin'@'localhost'(使用密码:否) [英] Warning: mysql_query(): Access denied for user 'admin'@'localhost' (using password: NO)
问题描述
好像我的 PHP
试图用用户名登录到 MySQL
数据库
我得到的错误是:
警告: mysql_query():拒绝用户'radiocaf'@'localhost'(使用密码:NO)在/home/radiocaf/public_html/layout.php在第16行
警告:mysql_query():指向服务器的链接无法在第16行的/home/radiocaf/public_html/layout.php中建立
我很确定提供一个密码,并没有使用radiocaf作为我的连接文件中的用户名,所以经过3个小时的盯梢,我仍然无法弄清楚我出错的地方。
以下是我的代码:
psl-config.php:
define(HOST,localhost);
define(USER,carl);
define(PASSWORD,xxxxxxxxx);
define(DATABASE,wlist);
db_connect.php
include_once'psl-config.php'; //不包含函数.php
$ mysqli = new mysqli(HOST,USER,PASSWORD,DATABASE);
然后最后,我接收错误的主要页面剪掉HTML之间的HTML:
ini_set('display_errors',1);
error_reporting (E_ALL);
//包含连接PHP和连接
include_once('includes / db_connect.php');
//检查连接
if($ mysqli - > connect_error){
die('Connection failed:'。$ mysqli-> connect_error);
};
if(!$ query = mysql_query(SELECT * FROM(
(SELECT * FROM users)
UNION ALL
(SELECT * FROM members)
)results
ORDER BY Name DESC)){
die(错误:。mysqli_error($ mysqli));
}
if(!$ result = $ mysqli-> query($ query)){
printf(Error :%s \ n,$ mysqli->错误);
}
< HTML>
echo< table border ='0 'cellpadding ='0'cellspacing ='0'>;
$ x = 0;
while($ row = mysql _fetch_assoc($ result)):
if($ x <10){
echo< tr>< td width ='400'height = '30'background ='.. / images / green1.jpg'>中[名称 ]。 < $行。; / TD>< / TR> 中;
}
$ x ++;
if($ x == 10){
echo< tr>< td width ='400'height'30'background ='.. / images / green1.jpg >更多...< / TD>< / TR>中;
休息;
}
endwhile;
echo< / table>;
< HTML>
$ mysqli-> close();
周围的 HTML
只是布局该页面基本上只是一个Photoshop布局,切片并导出到网页。
我对 PHP
相当陌生,所以我希望这个问题是尽可能解释。
编辑:
非常感谢这么多人,我很抱歉,这个问题对于你标记的一些人来说似乎很差。不幸的是,我不会看到拼写错误,因为我真的不知道我试图同时使用
mysql
和 mysqli
,并且他们不能相互沟通。我发现的另一个问题是Dreamweaver将 layout.php 中的代码作为 db_connect.php 上传。这不能解释(至少对我来说)如何建立任何连接来提供'radiocaf'@'localhost'的拒绝访问错误。 这里是( layout.php )中的旧代码行:
if(!$ query = mysql_query(SELECT * FROM(
while($ row = mysql_fetch_assoc($ result)):
更改为:
if(!$ query =SELECT * FROM(
while($ row = mysqli_fetch_assoc($ result)):
我非常感谢!再次感谢大家!
您正在冲突 MySQL
和 MySQLi
.MySQL和MySQLi是两种不同的方法
警告:
警告:mysql_query():.....
但是您将数据库连接到 mysqli
$ mysqli = new mysqli(HOST,USER,PASSWORD,DATABASE);.
在PHP 5.5.0中不推荐使用MySQL 扩展名,并且在PHP 7.0.0 即可。相反,
MySQLi
或PDO_MySQL
应该使用>扩展名。
It seems as though my PHP
is trying to log in to the MySQL
database with a username I am not supplying.
The error I am getting is:
Warning: mysql_query(): Access denied for user 'radiocaf'@'localhost' (using password: NO) in /home/radiocaf/public_html/layout.php on line 16
Warning: mysql_query(): A link to the server could not be established in /home/radiocaf/public_html/layout.php on line 16
I am definitely supplying a password, and am not using "radiocaf" as the username in my connect file, so after 3 hours of staring, I still can't work out where I am going wrong.
Here is my code:
psl-config.php:
define("HOST", "localhost");
define("USER", "carl");
define("PASSWORD", "xxxxxxxxx");
define("DATABASE", "wlist");
db_connect.php
include_once 'psl-config.php'; // As functions.php is not included
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
and then finally, the main page which is where I am receiving the error (I have cut out the HTML between the PHP:
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include Connection PHP and connect
include_once('includes/db_connect.php');
//Check Connection
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
};
if (!$query = mysql_query("SELECT * FROM (
(SELECT * FROM users)
UNION ALL
(SELECT * FROM members)
) results
ORDER BY Name DESC")){
die("Error: " . mysqli_error($mysqli));
}
if (!$result = $mysqli->query($query)){
printf("Error: %s\n", $mysqli->error);
}
<HTML>
echo "<table border='0' cellpadding='0' cellspacing='0'>";
$x=0;
while($row = mysql_fetch_assoc($result)):
if ($x<10){
echo "<tr><td width='400' height='30' background='../images/green1.jpg'>".$row["Name"]."</td></tr>";
}
$x++;
if ($x == 10){
echo "<tr><td width='400' height'30' background='../images/green1.jpg'>More...</td></tr>";
break;
}
endwhile;
echo "</table>";
<HTML>
$mysqli->close();
The surrounding HTML
is just the layout of the page, essentially just a photoshop layout, sliced and exported to web.
I am fairly new to PHP
and so I hope this question is as explained as possible.
Edit:
Thanks so much guys, I apologise that this question seemed poor to some of you that you flagged it. Unfortunately I wouldn't have seen the "typos" as I really didn't know that I was attempting to use both mysql
and mysqli
and that they couldn't "communicate" with each other. Another issue I found was Dreamweaver uploaded the code from layout.php as db_connect.php. This doesn't explain (to me at least) how any connection was being made to bring up the access denied error for 'radiocaf'@'localhost' though.
Here's the old code lines I changed (in layout.php):
if (!$query = mysql_query("SELECT * FROM (
while($row = mysql_fetch_assoc($result)):
changed to:
if (!$query = "SELECT * FROM (
while($row = mysqli_fetch_assoc($result)):
And that's all it took, but I am entirely grateful! Thanks again everyone!
You are conflicting MySQL
and MySQLi
. MySQL and MySQLi are two different methods
Warning is:
Warning: mysql_query(): .....
But you're connecting database with mysqli
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);.
Warning in php.net
:
MySQL extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the
MySQLi
orPDO_MySQL
extension should be used.
这篇关于警告:mysql_query():访问被拒绝用户'admin'@'localhost'(使用密码:否)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!