Warning: mysql_query(): Access denied for user 'admin'@'localhost' (using password: NO) [closed]

谁说我不能喝 提交于 2019-11-29 18:25:39
Abdulla Nilam

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.

Mayuresh
<?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 Connection
if ($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>
  <?php
    echo "<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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!