gpt4 book ai didi

php - PHP警告:mysql_fetch_array()期望参数1

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

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select




我正在创建用户个人资料,但发现一个问题。当我打开网址/链接时,得到警告:

Warning: mysql_fetch_array() expects parameter 1 to be resource, 
boolean given in *localhost/user_profiles/user_list.php* on line 9.


代码是:

<?php

function fetch_users(){

$result = mysql_query(
'SELECT `user_id` AS `id`, `user_username` AS `username` FROM `login`');

$users = array();

while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}

return $users;
}
?>

最佳答案

如其他人所建议,您的查询未成功执行。尝试使用以下代码来查明错误:

$result = mysql_query(
'SELECT `user_id` AS `id`, `user_username` AS `username` FROM `login`') or die (mysql_error());


请注意,可以将 or die()段放在PHP中的许多代码上,以调试代码并准确找出问题发生的位置。出于相同的原因, mysql_error()功能也很棒。

关于php - PHP警告:mysql_fetch_array()期望参数1 ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14306455/

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