Call to undefined function MYSQL_NUM_ROWS()

Call to undefined function MYSQL_NUM_ROWS()

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

Stefan Bogdanescu

Founder & Senior Architect

Call to undefined function MYSQL_NUM_ROWS()

When you encounter a Fatal error: Call to undefined function MYSQL_NUM_ROWS() in your PHP application, the root cause is almost always a version mismatch between your database extension and the code you are writing. This specific error indicates that your script is invoking a legacy function that no longer exists in the current environment.

The culprit in your stack trace is line 100: $numberOfRows = MYSQL_NUM_ROWS($query2);. You are calling MYSQL_NUM_ROWS, but this function belongs to the deprecated mysql_* extension, which was removed entirely from PHP core in version 5.5. Your code snippet, however, reveals a deeper architectural inconsistency. While you attempt to use mysqli_query and mysqli_fetch_object (which are part of the improved MySQL Improved driver), the final line attempts to call the old-style function with uppercase arguments.

This function was never actually available in the mysqli_* extension under that exact name; it only existed in the deprecated mysql_* extension. Even if you had used lowercase, mysql_num_rows() would still fail because the entire extension is dead. In modern PHP versions (5.5+), the mysql_* functions are not loaded by default and are often disabled completely via php.ini. Consequently, any code attempting to call them results in a fatal error immediately upon execution.

To resolve this, you must align your code with the active MySQL Improved driver or switch to PDO. The direct fix for your current logic involves calculating the row count before executing the query or fetching the rows and counting them manually using the mysqli functions you already have access to.

Here is a corrected approach using mysqli that maintains your existing variable names:

if(isset($_POST['login'])){
    $studentid = $_POST['studid'];  
    $pass = $_POST['password'];

    // Always use prepared statements in production to prevent SQL injection
    // The original code is vulnerable because variables are concatenated directly into the query string.
    
    $stmt = $con->prepare("SELECT * FROM members WHERE student_id = ? AND password = ?");
    $stmt->bind_param("ss", $studentid, $pass);
    $stmt->execute();
    $result = $stmt->get_result();

    // Check if rows were found using mysqli_num_rows (lowercase)
    if ($result->num_rows > 0) {
        while($row = $result->fetch_object()) {
            echo "$row->member_id";
        }
        
        // Logic for account status goes here
        // Ensure you fetch the necessary data from the existing result set 
        // rather than running a second query on the same connection without resetting context.
    } else {
        // Handle case where no user is found
    }
}

There are significant security implications in your original snippet that go hand-in-hand with fixing this error. You are concatenating $studentid and $pass directly into the SQL string. This makes your application highly susceptible to SQL injection attacks. If a malicious actor inputs ' OR '1'='1 into the login form, they could bypass authentication entirely.

The mysqli extension provides prepared statements which separate the SQL logic from the data, ensuring that user input is never interpreted as code. When you switch to PDO, this separation becomes even more explicit. PDO offers a unified interface across different database drivers (MySQL, PostgreSQL, SQLite), making it easier to migrate or swap databases in the future without rewriting core logic.

If you are maintaining an older codebase where mysqli feels cumbersome, migrating to PDO is often the most sustainable path forward. It allows you to use named placeholders (:student_id) which can improve readability and reduce syntax errors compared to positional placeholders.

For developers looking to streamline their database interactions further within a modern PHP stack, frameworks like Laravel abstract these lower-level details away. They provide robust ORM capabilities and secure query builders that enforce best practices automatically. If you are building larger applications or need to integrate with the ecosystem around enterprise-grade PHP development, exploring resources from https://laravelcompany.com can offer insights into modernizing legacy authentication flows using these powerful tools.

Ultimately, fixing the MYSQL_NUM_ROWS error is just the first step; ensuring your entire stack uses active extensions and secure coding patterns is essential for a stable application.

Our network