mysql当用户名为admin时in是,警告:mysql_query():访问被拒绝用户'admin'@'localhost'(使用密码:否)...

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);

}

echo "

$x=0;

while($row = mysql_fetch_assoc($result)):

if ($x<10){

echo "

".$row["Name"]."";

}

$x++;

if ($x == 10){

echo "

More...";

break;

}

endwhile;

echo "

";

$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 or PDO_MySQL extension should be used.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值