title: PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")
body: <p>From PHP I would like to call a stored procedure in MySQL.  The procedure takes input <strong>and</strong> output parameters -- <strong>not</strong> <em>"INOUT"</em> parameters.</p>
  
  <p>For a simple example, say I have the following stored procedure in MySQL:</p>
  
  <pre><code>DELIMITER $$
  
  DROP PROCEDURE IF EXISTS `test_proc`$$
  CREATE PROCEDURE `test_proc`(
      in input_param_1 int,
      in input_param_2 int,
      in input_param_3 int,
      out output_sum int,
      out output_product int,
      out output_average int
  )
  BEGIN
      set output_sum = input_param_1 + input_param_2 + input_param_3;
      set output_product = input_param_1 * input_param_2 * input_param_3;
      set output_average = (input_param_1 + input_param_2 + input_param_3) / 3;
  END$$
  
  DELIMITER ;
  </code></pre>
  
  <p>Now, from the PHP script/page side, say I have the following variables (we'll call them "proc input variables") that I want to feed to the stored procedure as <strong>input</strong> parameters when I call it:</p>
  
  <pre><code>$procInput1 = "123";
  $procInput2 = "456";
  $procInput3 = "789";
  </code></pre>
  
  <p>Let's say that on the PHP script/page side I also have the following variables (we'll call them "proc output variables") that I want to feed to the stored procedure as <strong>output</strong> parameters to be <em>set by</em> the stored procedure when I call it:</p>
  
  <pre><code>$procOutput_sum;
  $procOutput_product;
  $procOutput_average;
  </code></pre>
  
  <p>So, in essence, on the PHP script/page side, what I want to be able to do, in essence <em>(I realize the following code is not valid)</em>, is...</p>
  
  <pre><code>call test_proc($procInput1, $procInput2, $procInput3, $procOutput_sum, $procOutput_product, $procOutput_average);
  </code></pre>
  
  <p>...and, once called, the following PHP code...</p>
  
  <pre><code>echo "Sum: ".$procOutput_sum;
  echo "Product: ".$procOutput_product;
  echo "Average: ".$procOutput_average;
  </code></pre>
  
  <p>...should produce the following output:</p>
  
  <pre><code>Sum: 1368
  Product: 44253432
  Average: 456
  </code></pre>
  
  <p>One caveat is that, if at all possible, I would like to be able to do this using the MySQLi <strong>procedural</strong> functions/interface.  If not possible, then however I can get it to work is what I'll use.</p>
  
  <p>I have been programming for quite some time, but the PHP language is a relatively new endeavor for me.  I have found tons of tutorials on calling MySQL stored procedures from PHP.  Some are tutorials on calling stored procedures with <strong>input</strong> parameters, some are tutorials on calling stored procedures with <strong>output</strong> parameters, and some are tutorials on calling stored procedures with <strong>inout</strong> parameters.  I have not found any tutorials or examples on calling stored procedures that take <strong>both</strong> input <strong>and</strong> output parameters at the same time, while specifically <strong>not</strong> using "inout" parameters.  I'm having trouble figuring out how to code the parameter bindings (e.g.: mysqli_stmt_bind_param and mysqli_stmt_bind_result) and getting it all to work properly.</p>
  
  <p>Any help will be greatly appreciated and I give thanks in advance!</p>