Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling stored procedure with Out parameter using PDO
    text
    copied!<p>I've been using PDO for awhile now and am refactoring a project so that it uses stored procs instead of inline SQL. I am getting an error that I can't explain.I am using PHP version 5.3.5 and MySQL version 5.0.7.</p> <p>I'm just trying to get a basic stored proc with an output to work. Here is the stored proc:</p> <pre><code>DELIMITER // CREATE PROCEDURE `proc_OUT` (OUT var1 VARCHAR(100)) BEGIN SET var1 = 'This is a test'; END // </code></pre> <p>Here is the code I am using to call the proc, $db is an instance of PDO:</p> <pre><code>$stmt = $db-&gt;prepare("CALL proc_OUT(?)"); $stmt-&gt;bindParam(1, $return_value, PDO::PARAM_STR, 4000); // call the stored procedure $stmt-&gt;execute(); echo $returnvalue; </code></pre> <p>Simple right? However, it results in the following error:</p> <pre><code>exception 'PDOException' with message '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 </code></pre> <p>If I call the proc directly like so:</p> <pre><code>CALL proc_OUT(@res); SELECT @res; </code></pre> <p>it works as expected which leads me to believe that there is a problem with how it is being called with PHP, however I can't seem to find what the issue is. I am following the instructions in <a href="http://php.net/manual/en/pdo.prepared-statements.php" rel="nofollow noreferrer">the manual</a> but am still getting this error. Could anyone suggest what I could be doing wrong? Any advice would be very much appreciated. Thanks much!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload