php 致命错误:无法使用 mysqli_result 类型的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16525413/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:18:06  来源:igfitidea点击:

Fatal error: Cannot use object of type mysqli_result

phparraysmysqli

提问by Sergio Mironescu Iancu

I'm about to open my website when I noticed that one of my mods gives me this error:

当我注意到我的一个模组给我这个错误时,我正要打开我的网站:

Fatal error: Cannot use object of type mysqli_result as array in /var/www/vbsubscribetouser.php on line 303

致命错误:无法在第 303 行的 /var/www/vbsubscribetouser.php 中使用 mysqli_result 类型的对象作为数组

I've went to line 303 and this is what I found:

我去了第 303 行,这是我发现的:

//Check if requested username can be followed.
if (in_array($followingdata['usergroupid'], explode("|", $vbulletin->options['subscribetouser_usergroups_cannot']))){

Here is all the code starting at line 303:

这是从第 303 行开始的所有代码:

//Check if requested username can be followed.
if (in_array($followingdata['usergroupid'], explode("|", $vbulletin->options['subscribetouser_usergroups_cannot']))){
    exit;
}

if ($followinginfo[subscribers] > 0){
    $user_followers = $followinginfo[followers].$userinfo[userid].'|';
}
else{
    $user_followers = '|'.$userinfo[userid].'|';
}

$vbulletin->db->query_write("
    UPDATE " . TABLE_PREFIX . "user
    SET subscribers = subscribers + 1, `followers` = '$user_followers'
    WHERE userid = $followinginfo[userid]
");

I'm not an expert in php coding, so a bit of help would be great before opening the website. Any help/suggestions?

我不是 php 编码方面的专家,所以在打开网站之前获得一些帮助会很好。任何帮助/建议?

Thank you very much!

非常感谢!

回答by Kermit

Cannot use object of type mysqli_result as array

不能使用 mysqli_result 类型的对象作为数组

Use mysqli_fetch_assocor mysqli_fetch_arrayto fetch a result row as an associative array.

使用mysqli_fetch_assocmysqli_fetch_array获取结果行作为关联数组。

$query = "SELECT 1";
$result = $mysqli->query($query);
$followingdata = $result->fetch_assoc()

or

或者

$followingdata = $result->fetch_array(MYSQLI_ASSOC);