使用PHP PDO调用MySQL存储过程[重复]

时间:2022-08-21 16:40:44

This question already has an answer here:

这个问题在这里已有答案:

Trying to get to grips with stored procedures in MySQL/PHP. The SP works fine from the MySQL Console.

试图掌握MySQL / PHP中的存储过程。 SP可以从MySQL控制台正常工作。

But trying to call it in PHP, I get the following:

但是尝试用PHP调用它,我得到以下结果:

Fatal error: Cannot pass parameter 2 by reference in /home/dir/public_html/system/classes/account.class on line 92

致命错误:无法在第92行的/home/dir/public_html/system/classes/account.class中通过引用传递参数2

try {
  $dsn = 'mysql:dbname=db_name;host=localhost';
  $dbh = new PDO($dsn, 'usrName', 'password');
} catch (PDOException $e) {
  echo 'Connection failed: ' . $e->getMessage();
}

$stmt = $dbh->prepare("CALL db_name.stprNewUser(?,@statusValue)");
//$stmt->bindParam(1, 'user@googlemail.com', PDO::PARAM_STR); // <<LINE 92 DID NOT WORK
$stmt->bindValue(1, 'user@googlemail.com', PDO::PARAM_STR); // <<LINE 92 DID WORK

$stmt->execute();

1 个解决方案

#1


2  

From PDO tag wiki:

来自PDO标签维基:

If you don't know if you need bindValue() or bindParam(), go for the former. bindValue() is less ambiguous and has lesser side effects.

如果您不知道是否需要bindValue()或bindParam(),请选择前者。 bindValue()不那么模糊,副作用较小。

#1


2  

From PDO tag wiki:

来自PDO标签维基:

If you don't know if you need bindValue() or bindParam(), go for the former. bindValue() is less ambiguous and has lesser side effects.

如果您不知道是否需要bindValue()或bindParam(),请选择前者。 bindValue()不那么模糊,副作用较小。