Undetermined Function Invocation: "Fatal error: Call to undefined function mysqli_result()""
The provided code snippet attempts to migrate from MySQL to mysqli but encounters an error message indicating that the mysqli_result function is undefined. Let's delve into the cause and explore an alternative solution.
The original code utilized the mysql_result function, which is part of the deprecated MySQL extension. When switching to the MySQL Improved (mysqli) extension, you must replace the mysql functions with their mysqli counterparts. However, there is no direct equivalent for mysql_result in mysqli.
The solution lies in leveraging mysqli_fetch_assoc, a more efficient approach for retrieving data from a result set. The following modified code demonstrates this approach:
$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']; }
This single database operation eliminates the need for the multiple operations performed using mysql_result, resulting in improved efficiency.
The above is the detailed content of Why is `mysqli_result()` undefined and how can I efficiently retrieve data from a MySQLi result set?. For more information, please follow other related articles on the PHP Chinese website!