php 如何解决错误:“警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21060617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve error: "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result"?
提问by user3184656
I install Xampp on Windows 7, and try to select data from a database table. For this I create code like this:
我在 Windows 7 上安装 Xampp,并尝试从数据库表中选择数据。为此,我创建了这样的代码:
<?php
$con=mysqli_connect("localhost","test1","2jan1991","test1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br>";
}
mysqli_close($con);
?>
But when I try to run code it has error like:
但是当我尝试运行代码时,它有如下错误:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\t2\1.php on line 11
警告:mysqli_fetch_array() 期望参数 1 是 mysqli_result,布尔值在 C:\xampp\htdocs\t2\1.php 第 11 行给出
How to resolve this?
如何解决这个问题?
回答by kta
$result = mysqli_query($con, "SELECT * FROM Persons") or die("Error: " . mysqli_error($con));
Can tell you the reason.
可以告诉你原因。

