mysqli_stmt::fetch_array() Undefined Method Error Resolved
Facing an error "Fatal error: Call to undefined method mysqli_stmt::fetch_array()"? This error occurs when using prepared statements in PHP and attempting to retrieve data using the fetch_array() method. Here's the fix:
In your code, you use mysqli_stmt::prepare() to create a prepared statement. After executing the statement, you try to use mysqli_stmt::fetch_array() to fetch data into an associative array. However, this method is not available for prepared statements.
The correct method for fetching data from a prepared statement is mysqli_stmt::fetch(). Here's the corrected code:
<code class="php">$search = "player"; ($sql = $db->prepare('select job from jobs where job like ?')); $sql->bind_param('s', $search); $sql->execute(); $sql->bind_result($search); $data = array(); while ($sql->fetch()) { $data[] = array( 'label' => $row['job'] ); echo json_encode($data); } $sql->close(); $db->close();</code>
The above is the detailed content of Why am I getting a \"Fatal error: Call to undefined method mysqli_stmt::fetch_array()\"?. For more information, please follow other related articles on the PHP Chinese website!