Call to undefined method PDO::bindParam()

Can someone tell me why I am getting this error? Call to undefined method PDO::bindParam()

Here is what I have, taken right off of PHPs site for stored procedures

$stmt = db::getInstance();
$stmt->prepare("CALL delete(?)");
$stmt->bindParam(2122, $return_value, PDO::PARAM_STR, 4000);
$stmt->execute();
print "procedure returned $return_value\n";

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

The bindParam() method is inside the PDOStatement class, not the PDO class. The statement is the result of the prepare() method.

$foo = db::getInstance();
$stmt = $foo->prepare("CALL delete(?)");
$stmt->bindParam(2122, $return_value, PDO::PARAM_STR, 4000);
$stmt->execute();
print "procedure returned $return_value\n";

Solution 2

The bindParam() function is a method of a PDOStatement object, not a PDO object. $stmt is an object of class PDO. You’ll have to use the PDOStatement from your prepare() call instead.

$pdo = db::getInstance();
$stmt = $pdo->prepare("your query");
$stmt->bindParam(2122, $return_value, PDO::PARAM_STR, 4000);

Solution 3

$stmt = db::getInstance(); 
$query = $stmt->prepare("CALL delete(?)"); 
$query->bindParam(2122, $return_value, PDO::PARAM_STR, 4000); 
$query->execute();

You need to be calling PDOStatment::bindParam. The prepare method returns the PDOStatment Object. The PHP PDO/PDOStatment manuals should help.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply