Fatal Error: Call to a Member Function Bindparam()

On a function that gets settings from a DB I ran into the error

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.)

Fatal error: Call to a member function bindParam() on string

change :

$sql = "UPDATE users SET name=:name WHERE id=$id";
$sql->bindParam(":name", $name);
$consulta = $db->prepare($sql);

to

$sql = "UPDATE users SET name=:name WHERE id=:id";
$consulta = $db->prepare($sql);
$consulta->bindParam(":name", $name, PDO::PARAM_STR);
$consulta->bindParam(":id", $id, PDO::PARAM_INT);

Call to a member function bind_param() on boolean error in PHP--MySQL

First turn on error reporting by adding the below two lines at the top of your page. Then try printing out the exact error by doing echo $mysli->error;

error_reporting(E_ALL);
ini_set('display_errors', 1);

$mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
$statement = $mysqli->prepare("INSERT INTO brickTable (url, description) VALUES(?,?)");
echo $mysqli->error;
$statement->bind_param("ss", $_POST["url"], $_POST["description"]);
$statement->execute();

It will tell you the error.

PHP Fatal error: Call to a member function bind_param()

Since nobody else has spotted the issue, I'll post it for you. The reason you're prepare() is failing is because you're trying to use a MySQL Reserved Word. The word desc is a reserved word in MYSQL, which means you need to wrap it in backticks like this:

$statement= $db->prepare("insert into uploaddetails(idnum,title,`desc`,author,tags,file) values(?,?,?,?,?,?)");

It also helps to use proper practice when inserting into a database/using prepared statements.

$statement= $db->prepare("insert into uploaddetails(idnum,title,`desc`,author,tags,title) values(?,?,?,?,?,?)");

if($statement !== FALSE) {
// do the binds...etc
}

Notes

file is also a reserved word, I don't know what your actual file columns name is, so keep that in mind.

Fatal error: Call to a member function bindParam()

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();
}

Call to a member function bind_param() on boolean

<?php
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade)
VALUES (?, ?, ?, ?)");
if (!$stmt) {
echo "false";
}
else {
$stmt->bind_param("ssss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment, $protectiveGrade);
$stmt->execute();
}

if ($stmt = false) means you're assigning false to $stmt. Replace it with if (!$stmt).

You're binding 4 parameters but only providing 3 types of values. I added a s in the bind_param function, assuming all your values are string. If some of the values are integers replace the corresponding s with an i. If there are doubles, replace with a d.

Are you sure the first field's name in the assignments table is Classes_has_Subjects_classesHasSubjectsId?

Fatal error: Uncaught Error: Call to a member function bindParam() on string i

you have to bind params on prepared statement. change select query statement to

$query = $connection->prepare("SELECT * FROM users where email = :email AND username = 
:username");

EDIT

To count number of rows from select query use fetchColumn. Also you are assigning value to $count1 and using $count. So use same variable name

$count = $query->fetchColumn();
if($count> 0)
{
echo "soryy the email you are trying to register is already
registered!";
}

PHP - Fatal error: Call to a member function bind_param()

TL\DR

Your query is failing to prepare(). You need to figure out where, how and why. Look at the last code block of this answer and let us know what the error is.


I'll start with the query. You're trying to access a MySQL reserved word Source (See #684). You need to wrap those in backticks like this:

$add = "INSERT INTO books (title, edited, created, ip,".
" email_to, twitter, last_taken, questions_total, responses, ".
"show_progress, need_correct, go_back, state, send_stats, ".
"show_number, imported) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ".
"?, ?, ?, ?, ?, ?, ?)";

Now, you're instantiating the variable $stmt within the if block but then trying to bind it outside of that block. You'll need to change this:

if ($stmt = $mysqli->prepare($add)) {
....
}
$stmt->bind_param(....);

To this:

if ($stmt = $mysqli->prepare($add)) {
....
$stmt->bind_param(....);
}

Also, make sure your query is actually preparing correctly:

if ($stmt = $mysqli->prepare($add)) {

$stmt->bind_param("siisssiiiiiiiiii", $title, $edited, $created, $ip, $email_to, $twitter, $last_taken, $questions_total, $responses, $show_progress, $need_correct, $go_back, $state, $send_stats, $show_number, $importedVal);

// execute it and all...
} else {
die("Errormessage: ". $mysqli->error);
}

Then let us know what turns up.

Call to a member function bind_param() on a non-object

as the error-message says, $qSelect seems to be not an object. try to debug this by using var_dump($qSelect); right after your prepare-call. also check if getDBH() returns what you need.

sounds like the prepare-call fails (don't know why) and so it returns false - false is not an object, so you can't call bind_param() on that.

EDIT: you havn't given the info, but it looks like you're using PHP's PDO. In that case, take a look at the documentation.

If the database server successfully
prepares the statement, PDO::prepare()
returns a PDOStatement object. If the
database server cannot successfully
prepare the statement, PDO::prepare()
returns FALSE or emits PDOException
(depending on error handling).

You should configure your server to return those PDO-Exceptions, which would tell you why the prepare call fails.



Related Topics



Leave a reply



Submit