Warning: Mysql_query(): Access Denied For User 'admin'@'localhost' (using Password: No)
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 'r
Solution 1:
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.
Solution 2:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include Connection PHP and connect//include_once('includes/db_connect.php');$con=mysqli_connect(HOST, USER, PASSWORD, DATABASE);
//Check Connectionif ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
};
if (!$query = mysqli_query($con,"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><body><?phpecho"<table border='0' cellpadding='0' cellspacing='0'>";
$x=0;
while($row = mysqli_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>";
$mysqli->close();
?></body><HTML>
Post a Comment for "Warning: Mysql_query(): Access Denied For User 'admin'@'localhost' (using Password: No)"