Home > Database > Mysql Tutorial > body text

How to Fix 'OUT or INOUT argument...is not a variable' Error When Calling Stored Procedures with PDO?

Susan Sarandon
Release: 2024-11-07 05:21:03
Original
207 people have browsed it

How to Fix

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:

  1. In the stored procedure, add a SELECT statement for the output parameter. For example:
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 //  
Copy after login
  1. In your PHP code, use the normal PDO execute() method to call the stored procedure without binding the output parameter:
$stmt = $db->prepare("CALL proc_OUT(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
$stmt->execute();
Copy after login
  1. After executing the stored procedure, retrieve the output parameter using a separate query() call:
$result = $db->query("SELECT var1 FROM proc_OUT");
foreach ($result as $row) {
    echo $row['var1'];
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!