我收到了这个警告
警告:mysqli_connect():( HY000 / 1045):第14行的C:\ wamp \ www \ S_WEB \ connection \ dbcon.php中的用户“root”@“localhost”(使用密码:YES)拒绝访问`
我的表users
是:
我的查询user
的代码是:
<?php
//Connect to database
$servername = "127.0.0.1";
$username = "root";
$password = "root";
$dbname = "s_web";
// Create connection
$db = mysqli_connect('127.0.0.1','root','root','s_web')
or die('Error connecting to MySQL server.');
$query = "SELECT * FROM user" ;
mysqli_query($db, $query) or die('Error querying database');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['username'] . ' ' . $row['password'] . '<br />';
}
?>
我的问题是,当我尝试使用mysqli建立连接数据库时出现错误。 我在那里遇到很多错误。最近两天我试图解决我的问题,但我没有。
答案 0 :(得分:0)
更新回答:
<?php
//Connect to database
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "s_web";
// Create connection
$db = mysqli_connect($servername,$username,$password,$dbname)
or die('Error connecting to MySQL server.');
//as per error table user doesn't exist in the database, actual table name users
$query = "SELECT * FROM users" ;
//You're running same query twice that's why I commented one
//mysqli_query($db, $query) or die('Error querying database');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['username'] . ' ' . $row['password'] . '<br />';
}
?>