gpt4 book ai didi

php - 警告 : mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool 值在第 21 行/... 中给出

转载 作者:行者123 更新时间:2023-11-29 17:21:05 25 4
gpt4 key购买 nike

过去 2 个小时我一直在尝试解决这个错误。我是一个完全的菜鸟,所以我不知道发生了什么。代码如下,请帮忙:

<?php
header('Access-Control-Allow-Origin: *');




$host="localhost"; // Host name
$username="id11111_ab"; // Mysql username
$password="*****"; // Mysql password
$db_name="id11111_cd"; // Database name
$tbl_name="ef"; // Table name

// Connect to server and select database.
$link = mysqli_connect($host, $username, $password, $db_name);

// Retrieve data from database
$sql = "SELECT * FROM scores ORDER BY score DESC LIMIT 10";
$result = mysqli_query($link,$sql);

// Start looping rows in mysql database.
while($rows=mysqli_fetch_array($result)){
echo $rows['name'] . "|" . $rows['score'] . "|";

// close while loop
}
?>

最佳答案

mysqli_query()如果失败则返回false。随后,mysqli_fetch_array() 函数将传递这个 false bool 值,该函数无法对其进行操作。在尝试检索资源之前,最好检查 mysqli_query() 返回的值是否为 false。例如:

$result = mysqli_query($link,$sql);
if (!$result) {
die('Query failed');
}

关于php - 警告 : mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool 值在第 21 行/... 中给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51249792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com