Home >Backend Development >PHP Tutorial >Why is My MySQLi `bind_param()` Function Throwing a 'Call to a Member Function on a Non-Object' Error?
Problem:
MySQLi is throwing a "Call to a member function bind_param() on a non-object" error when attempting to update columns in a table using the bind_param() method.
Cause:
The bind_param() method can only be called on a valid mysqli_stmt object. The error occurs because the mysqli_stmt object is not being created properly.
Solution:
To resolve this error:
Example with PDO:
<?php try { // Create PDO connection $pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password'); // Prepare update statement $stmt = $pdo->prepare("UPDATE questionnaire SET $key = ? WHERE id = ?"); // Bind parameters $stmt->bindParam(1, $value, PDO::PARAM_STR); // Set the value parameter $stmt->bindParam(2, $rowid, PDO::PARAM_INT); // Set the rowID parameter // Execute update $stmt->execute(); } catch (PDOException $e) { trigger_error($e->getMessage(), E_USER_ERROR); }
The above is the detailed content of Why is My MySQLi `bind_param()` Function Throwing a 'Call to a Member Function on a Non-Object' Error?. For more information, please follow other related articles on the PHP Chinese website!