Home >Database >Mysql Tutorial >How to Fix 'OUT or INOUT argument...is not a variable' Error When Calling Stored Procedures with PDO?
Calling Stored Procedure with Out Parameter Using PDO: Resolved Bug
Despite following the PDO manual, you may encounter an "OUT or INOUT argument...is not a variable" error when calling a stored procedure with an output parameter. This is likely due to a bug in earlier versions of PHP and MySQL.
To resolve this issue, implement the following workaround:
DELIMITER // CREATE PROCEDURE `proc_OUT` (OUT var1 VARCHAR(100)) BEGIN SET var1 = 'This is a test'; SELECT var1; -- Select added to retrieve the output parameter END //
$stmt = $db->prepare("CALL proc_OUT(?)"); $stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000); $stmt->execute();
$result = $db->query("SELECT var1 FROM proc_OUT"); foreach ($result as $row) { echo $row['var1']; }
The above is the detailed content of How to Fix 'OUT or INOUT argument...is not a variable' Error When Calling Stored Procedures with PDO?. For more information, please follow other related articles on the PHP Chinese website!