"fatal error: call to a member function bindparam()" Answer’s


I would check that the $db->prepare() function executed successfully. It will return false if it did not. So you could be trying to call bindParam() on a variable that equals false


Also you should put the PDO object declaration in try/catch to be sure it was successful as well, as in the first example on this page:

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
Wednesday, March 31, 2021
answered 11 Months ago

the query fail and dont return the prepared stament look,


change to

Friday, May 28, 2021
answered 9 Months ago

As I stated in comments, you didn't choose a database.

As requested:

This line:

$db = new mysqli("localhost","root","");

Should have read as:

$db = new mysqli("localhost","root","", "database");

and replacing "database" with the name of your database.

The documentation can be found at the following address on PHP.net:

  • http://php.net/manual/en/function.mysqli-connect.php

Example pulled from the manual along with error checking:

$link = mysqli_connect("", "my_user", "my_password", "my_db");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;


Note: Alhough you can still theoretically connect, you just wouldn't be able to query anything though. That's where error checking is important during development testing.

Saturday, May 29, 2021
answered 9 Months ago

Your function will end/return as soon as it hits the first return statement in the loop (first iteration). You will need to build the complete array and then return it once.

This ought to do it:

    return ["Prepare failed: ".mysqli_error($mysqli)];  // what does this say?
    return ["Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error];
    $u = $username;
    $p = $password;
    $uu = $username;
    $pp = $password;
    if (!$stmt->execute()){
        return ["Execute failed: (" . $stmt->errno . ") " . $stmt->error];
        $result = $stmt->get_result();
        while($row = $result->fetch_array(MYSQLI_ASSOC)){
        return $rows;

Try backticking all of your column names. LEVEL is a MySQL KEYWORD.

Saturday, May 29, 2021
answered 9 Months ago

The problem lies in:

$query = $this->db->conn->prepare('SELECT value, param FROM ws_settings WHERE name = ?');
$query->bind_param('s', $setting);

The prepare() method can return false and you should check for that. As for why it returns false, perhaps the table name or column names (in SELECT or WHERE clause) are not correct?

Also, consider use of something like $this->db->conn->error_list to examine errors that occurred parsing the SQL. (I'll occasionally echo the actual SQL statement strings and paste into phpMyAdmin to test, too, but there's definitely something failing there.)

Tuesday, June 1, 2021
answered 9 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :