我正在尝试从数据库加载数据,但它显示错误 “致命错误:未捕获错误:在布尔值上调用成员函数fetch_array()” 请帮我解决这个错误。
<!DOCTYPE html>
<?php include 'db.php'; ?>
<html>
<head>
<title>Chat System in PHP</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all"/>
</head>
<body>
<div id="Container">
<div id="Chat_box">
<?php
$query = "SELECT * FROM chat_system ORDER BY id DESC";
$run = $db->query($query);
while($row = $run-> fetch_array()):
?>
<div id="Chat_data">
<span style="color:blue;"> <?php echo $row ['name']; ?> </span>:
<span style="color:brown;"><?php echo $row ['msg']; ?></span>
<span style="float:right; color:silver;"><?php $row['date'];?>
</span>
</div>
<?php endwhile; ?>
</div>
<form action="index.php" method="POST">
<input type="text" name="name" placeholder="Enter Name">
<textarea name="msg" placeholder="Enter Message"></textarea>
<input type="submit" name="submit" value="Send">
</form>
</div>
</body>
</html>
这是数据库连接的db.php文件..
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "chat_system";
$db = new mysqli($host,$user,$pass,$db_name);
?>
答案 0 :(得分:0)
在php docs中,您可以阅读
失败时返回FALSE。对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回一个mysqli_result对象。对于其他成功的查询,mysqli_query()将返回TRUE
您可能在查询或数据库连接中有错误...您可以共享表结构并验证数据库连接参数吗?