我正在尝试使用PHP连接到我的MySQL服务器,但我一直收到“无法获得结果”。在我的网页上。这是我正在使用的代码。
<?PHP
error_reporting(1);
//Connect to MySQL server.
$mysqli = new MySQLi('localhost', 'username', 'password', 'login') or die(mysql_error());
//Query the database.
$result = $mysqli->query("SELECT * FROM users");
//Count the returned rows.
if($result->num_rows != 0){
//Convert query into array.
while($rows = $result->fetch_asocc()) {
$id = $rows['ID'];
$username = $rows['Username'];
$email = $rows['Email'];
$password = $rows['Password'];
//Display results.
echo "ID: $id\nUsername: $username\nE-Mail: $email\nPassword: $password\n";
}
} else {
echo "Failed to get results.";
}
?>