title: Retrieving OUT paramters from stored procedures PHP and MariaDB MySQL
body: <p>When calling a stored procedure from PHP, the following code produces the correct results but is it possible to bind the two OUT parameters rather than holding them in @result and @id_ssn and then executing another statement to select them?</p>
  <pre><code>    $stmt = $db-&gt;stmt_init();
      $stmt = $db-&gt;prepare(&quot;call logger(?,?,?,?,@result,@id_ssn);&quot;);
      $stmt-&gt;bind_param( 'ssss', $id_log, $u, $p, $ip );
  
      if ( !$stmt-&gt;execute() ) {
        throw new Exception(&quot;Failed to execute stored procedure logger().&quot;, 2);
      }
  
      $stmt-&gt;free_result();
      $stmt = $db-&gt;stmt_init();
      $stmt = $db-&gt;prepare(&quot;select @result, @id_ssn;&quot;);
  
      if ( !$stmt-&gt;execute() ) {
        throw new Exception(&quot;Failed to execute query to get results of logger().&quot;, 3);
      }
  
      $stmt-&gt;store_result();
  
      if ( $stmt-&gt;num_rows == 0 ) {
        throw new Exception(&quot;No results in logger().&quot;, 4);
      }
  
      $stmt-&gt;bind_result($res,$id_ssn);
      $stmt-&gt;fetch();
  </code></pre>
  <p>When calling a stored procedure from within a stored procedure the following one line of code produces the correct result, but is it possible to retrieve the OUT parameter to a variable declared in the outer procedure rather than an @r_usr?</p>
  <p><code>call str_proc( id_mbr, '01', @r_usr );</code></p>
  <p>This <a href="https://stackoverflow.com/questions/23747835/mysql-retrieve-variable-from-stored-procedure-in-php-pdo">SO question</a> has a reference to a Example 4 of a <a href="https://www.php.net/pdo.prepared-statements" rel="nofollow noreferrer">PHP page</a> that uses the PDO layer to get the OUT parameters.  I've been using PHP and MariaDB for about two weeks now and know very little; and nothing about the PDO which I don't think I'm using, at least not referencing it in my code directly.</p>
  <p>Thank you.</p>
  <p><strong>EDIT:</strong>
  This question was closed as a duplicate but the question referenced provides nothing more than the code provided in my question.  My question concerns whether or not there is a better method as the SO question and PHP page links provided bring up but do not resolve.  Unless, of course, the answer is simply that this is the best or only approach other than the PDO.</p>
  <p>In the SO question referenced in my question that asker takes the position that if the OUT parameters must be received into user-defined variables and then a second statement executed to write them to PHP variables, he could've have just retrieved them from the database in the second statement and not included OUT parameters in the stored procedure.  I don't know much but it would appear that, although that is correct, a statement to write the user-defined variables to PHP variables is simpler than querying the table or tables again.</p>
  <p>Then there is the PDO approach given in the aforementioned Example 4.  Is it more efficient or just easier to write?</p>
  <p>Thus, the proposed duplicate is not a duplicate question apart from the title, which I likely should have made more specific to make it clear that it wasn't asking just how can the OUT parameters be retrieved but the right or most efficient method.</p>
  <p>Thank you.</p>