Fatal error: Call to undefined function mysqli_result()

Fatal error: Call to undefined function mysqli_result()

  1. Blog
  2. 15 November 2026
  3. 2 min read

Stefan Bogdanescu

Founder & Senior Architect

Fatal error: Call to undefined function mysqli_result()

This specific Fatal error is a classic symptom of migrating from legacy PHP code to modern standards without updating the underlying API usage patterns. The confusion arises because the transition from the deprecated mysql_* extension to mysqli was not always a direct 1:1 mapping. While many helper functions share names and similar signatures, the internal implementation details changed significantly, specifically regarding how data is retrieved from result sets.

In your original code using the mysql_* functions, $ID = mysql_result($result, $i, "ID") retrieves a specific column by passing an integer row index and a string column name. This function was designed to work with a resource-based result set where the pointer was advanced sequentially or accessed directly via integer indices.

However, in your migrated code using mysqli, you are encountering the error because mysqli_result() does not exist as a standalone function for retrieving data in the way you attempted. The mysqli extension shifted away from procedural "result row" functions that take an index and a column name as separate arguments for direct access. Instead, it enforces a stricter separation between fetching rows and accessing columns.

To resolve this without switching to object-oriented syntax (which is often preferred for its clarity), you must use mysqli_fetch_assoc() or mysqli_fetch_row(). These functions return an array representing the current row in the result set. Once you have that array, you can access individual columns using their names as keys.

Here is how your corrected procedural code should look:

$query = "SELECT * FROM `product_category`";
$result = mysqli_query($connect, $query) or die("could not perform query");

// Fetch the first row to determine total rows if needed, 
// though mysqli_num_rows() returns the count before fetching.
$num_rows = mysqli_num_rows($result);

for ($i = 0; $i < $num_rows; $i++) {
    // We must fetch the row first to move the internal pointer
    $row = mysqli_fetch_assoc($result);
    
    // Now access columns by their name as keys in the returned array
    $ID = $row['ID'];
    $name = $row['name'];
    $description = $row['description'];
}

The critical change is replacing mysqli_result($result, ...) with mysqli_fetch_assoc($result). In the mysqli API, you cannot directly index a result object like an array to get a row while simultaneously specifying a column name in a single function call. The library expects you to retrieve the entire row as an associative array first.

It is also worth noting that mysql_num_rows() behaves differently depending on whether you have fetched rows previously. In the legacy mysql_* extension, calling mysql_num_rows() would not advance the result pointer. However, in mysqli, once you iterate through the results or fetch a row, the internal pointer moves. If you rely on mysqli_num_rows() to know how many loops to run, you must ensure you are iterating correctly. In modern development, it is often more robust to check for the existence of a row inside the loop rather than pre-calculating the count, as this avoids issues with large result sets or cursor exhaustion in some database drivers.

Furthermore, relying on numeric indices (like $i) in mysqli procedural calls without fetching the row first leads to errors because the function signature changed. The old mysql_result() accepted an index and column name, but mysqli requires you to fetch the row object first.

If you are building a larger application where procedural code feels cumbersome, consider switching to the object-oriented interface of mysqli. It allows for more intuitive handling of result sets:

$stmt = $connect->prepare("SELECT * FROM `product_category`");
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    // Accessing columns by name is cleaner and less prone to errors
    echo "ID: {$row['ID']}, Name: {$row['name']}";
}

This approach eliminates the need for manual loop counters and makes the code self-documenting. For those maintaining legacy systems or working with specific constraints, understanding this API shift is crucial. If you are starting a new project using these concepts within a larger ecosystem, frameworks like Laravel provide robust wrappers that abstract these differences away entirely. For more guidance on migrating database logic safely, resources such as https://laravelcompany.com offer detailed documentation on best practices for handling data access in modern PHP stacks.

Our network