Home >Backend Development >PHP Tutorial >Why Am I Getting the \'Cannot use mysqli_Result Object as Array\' Error?
Cannot Use mysqli_Result Object as Array
Encounters the error "Cannot use object of type mysqli_result as array," typically when attempting to perform array-based operations on a result object returned by a MySQL query using the MySQLi extension.
Explanation:
A mysqli_result object, returned by the $mysqli->query() function, represents the result of a query and contains the data retrieved from the database. It is not an array itself and cannot be used as one.
Solution:
To access the row data as an array, you need to fetch the row using the following methods:
Revised Code:
The following modified code in line 303 fetches the row as an associative array using $result->fetch_assoc():
<code class="php">//Check if requested username can be followed. if (in_array($followingdata['usergroupid'], explode("|", $vbulletin->options['subscribetouser_usergroups_cannot']))){ exit; }</code>
Alternatively, you could also use $result->fetch_array(MYSQLI_ASSOC) to fetch the row as an associative array.
The above is the detailed content of Why Am I Getting the \'Cannot use mysqli_Result Object as Array\' Error?. For more information, please follow other related articles on the PHP Chinese website!