如何解决错误:“警告:mysqli_fetch_array()期望参数1是mysqli_result”?

时间:2014-01-11 09:22:44

标签: php

我在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);
?>

但是当我尝试运行代码时,它有如下错误:

  

警告:mysqli_fetch_array()要求参数1为mysqli_result,第11行的C:\ xampp \ htdocs \ t2 \ 1.php中给出布尔值

如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

$result = mysqli_query($con, "SELECT * FROM Persons") or die("Error: " . mysqli_error($con));

可以告诉你原因。