


Why Does \'Fatal error: Call to undefined method mysqli_stmt::fetch_array()\' Occur When Using Prepared Statements?
Nov 02, 2024 am 01:24 AMFixing "Fatal error: Call to undefined method mysqli_stmt::fetch_array() [duplicate]"
In your code, you're attempting to use mysqli_stmt::fetch_array() when using prepared statements. This function is not available for prepared statements.
Solution:
Instead, you should use mysqli_stmt::fetch() to retrieve a single row of data, or mysqli_result::fetch_all() to retrieve multiple rows.
Revised code:
<code class="php">$search = "player"; $sql = $db->prepare('select job from jobs where job like ?'); $sql->bind_param('s', $search); $sql->execute(); $result = $sql->get_result(); // Get the result object $data = array(); while ($row = $result->fetch_assoc()) { $data[] = array( 'label' => $row['job'] ); echo json_encode($data); } $sql->close(); $db->close();</code>
By using mysqli_stmt::fetch_array() or mysqli_result::fetch_assoc(), you can retrieve the data from the database successfully without encountering the error.
The above is the detailed content of Why Does \'Fatal error: Call to undefined method mysqli_stmt::fetch_array()\' Occur When Using Prepared Statements?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I configure SSL/TLS encryption for MySQL connections?
