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

0

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

http://www.php.net/manual/en/pdo.prepare.php

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
 
turson
answered 11 Months ago
0

the query fail and dont return the prepared stament look,

VALUES(?,?,?,?,?,?,?.?)

change to

VALUES(?,?,?,?,?,?,?,?)
Friday, May 28, 2021
 
leebriggs
answered 9 Months ago
0

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:

<?php
$link = mysqli_connect("127.0.0.1", "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;
    exit;
}

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;

mysqli_close($link);

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
 
Powering
answered 9 Months ago
0

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:

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

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

Saturday, May 29, 2021
 
Floris
answered 9 Months ago
0

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
 
Norgul
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 :