开发者

Call to undefined method PDO::bindParam()

开发者 https://www.devze.com 2022-12-16 20:14 出处:网络
Can someone tell me why I am getting this error? Cal开发者_如何学Pythonl to undefined method PDO::bindParam()

Can someone tell me why I am getting this error? Cal开发者_如何学Pythonl 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";


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";


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号