Home > Database > Mysql Tutorial > body text

Why Does My MySQLi Code Throw a \'Fatal error: Call to undefined function mysqli_result()\' Error?

Linda Hamilton
Release: 2024-11-17 20:02:02
Original
246 people have browsed it

Why Does My MySQLi Code Throw a

Fatal Error in Migrating from MySQL to MySQLi: Call to Undefined Function mysqli_result()

When attempting to update an old SQL query using MySQLi, developers may encounter a "Fatal error: Call to undefined function mysqli_result()" error. This occurs when using the mysqli_result() function, which is not available in MySQLi.

To resolve this error, it is crucial to recognize that mysqli_result() is an obsolete function that should not be employed for modern database operations. Instead, the recommended alternative is to utilize mysqli_fetch_assoc(), which provides a more efficient single operation.

The updated code should resemble the following:

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

for ($i=0; $i < $num_rows; $i++)
{
    $row = mysqli_fetch_assoc($result);
    $ID = $row['ID'];
    $name = $row['name'];
    $description = $row['description'];
}
Copy after login

By adhering to this approach, developers can avoid the undefined function error and establish an efficient communication with their database using MySQLi.

The above is the detailed content of Why Does My MySQLi Code Throw a \'Fatal error: Call to undefined function mysqli_result()\' Error?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template