Understanding the "Fatal Error: Call to Undefined Function mysqli_result()" Exception in PHP
When attempting to switch from the deprecated mysql functions to sqli in PHP, you may encounter the error "Fatal error: Call to undefined function mysqli_result()". This error occurs when you try to access the result of a MySQL query using the mysqli_result() function, which is not available in the updated mysqli extension.
Solution: Using mysqli_fetch_assoc()
To resolve this issue, avoid directly accessing the result using mysqli_result() and instead use the mysqli_fetch_assoc() function to retrieve the data in an associative array. This function iterates through the result set and returns the next row as an associative array, making it more efficient and compatible with the mysqli extension. Here's how you can rewrite your code using mysqli_fetch_assoc():
$query = "SELECT * FROM `product_category`"; $result = mysqli_query($connect, $query) or die("could not perform query"); $num_rows = mysqli_num_rows($result); while($row = mysqli_fetch_assoc($result)) { $ID = $row['ID']; $name = $row['name']; $description = $row['description']; }
Benefits of mysqli_fetch_assoc()
Using mysqli_fetch_assoc() offers several advantages:
The above is the detailed content of Why Does My PHP Code Throw a \'Fatal Error: Call to Undefined Function mysqli_result()\'?. For more information, please follow other related articles on the PHP Chinese website!