Calling Stored Procedure with Output Parameter Using PDO
When attempting to execute a stored procedure with an output parameter using PDO, it's essential to consider a known bug. This bug can lead to the following error, despite the procedure working as expected when directly called from MySQL:
"SQLSTATE[42000]: Syntax error or access violation: 1414 OUT or INOUT argument 1 for routine mydb.proc_OUT is not a variable or NEW pseudo-variable in BEFORE trigger"
To resolve this issue, it is recommended to execute the stored procedure using the following approach:
$dbh->query("CALL SomeStoredProcedure($someInParameter1, $someInParameter2, @someOutParameter)"); $dbh->query("SELECT @someOutParameter");
$stmt = $dbh->prepare("CALL SomeStoredProcedure(?, ?)"); $stmt->execute(array($someInParameter1, $someInParameter2));
By following this approach, you can effectively call stored procedures with output parameters using PDO, even in the presence of the aforementioned bug.
The above is the detailed content of How to Call Stored Procedures with Output Parameters Using PDO When Encountering a Known Bug?. For more information, please follow other related articles on the PHP Chinese website!