Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MySQL PDO stored procedures and INOUT parameters
    primarykey
    data
    text
    <p>I am using some stored procedures against a datastore shared by more than one application and need to call a stored procedure that has an <code>INOUT</code> parameter.</p> <p>From documentation this would work something like</p> <pre><code>$prob_param = null; $stmt = $pdo-&gt;prepare('CALL obnoxiousStoredProc(:problem_param)'); $stmt-&gt;bindParam(':problem_param', $prob_param, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 11); $stmt-&gt;execute(); echo 'Prob param: ' . var_export($prob_param, true); </code></pre> <p>And we would see something like</p> <pre><code>Prob param: int(420) </code></pre> <p>BUT <strong>There is a bug</strong> that prevents this from working as expected <a href="https://stackoverflow.com/a/4502524/701368">See this answer</a>. </p> <p>So instead we get </p> <pre><code>Syntax error or access violation: 1414 OUT or INOUT argument $parameter_number for routine $procedure_name is not a variable or NEW pseudo-variable </code></pre> <p>The workaround, as described in the answer is two-fold, separate your input and output parameters (which I can get my DBA to do) and use local variables</p> <p>e.g.</p> <pre><code>$stmt = $pdo-&gt;prepare('CALL obnoxiousStoredProc(@problem_param)'); </code></pre> <p>and then use a second query</p> <pre><code>SELECT @problem_param </code></pre> <p>To get your value.</p> <p><strong>My question is: what is the scope of this "local variable" in PDO? Am I setting myself for a race condition if my php code is getting simultaneously?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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