title: Returning the output parameter of a mysql stored procedure using PHP
body: <p>I'm planning on developing a CMS using PHP and MySQL that utilises MySQL stored procedures to perform prepared statement queries to my MySQL database. It's been a long time since I developed in PHP (back in the procedural days) so I'm going to try and implement this system using the new OOP structure of PHP. Before I do that, I need to get to grips with the simple issue of returning the output parameter of my MySQL stored procedure to a simple php page. This is simply a test so that I can get the syntax correct before developing my first php class so the initial code posted here is procedural. </p>
  
  <p>First, there is my stored procedure:</p>
  
  <pre><code>    DELIMITER $$
      DROP PROCEDURE IF EXISTS `text_development`.`get_user`$$
      CREATE PROCEDURE  `text_development`.`get_user`
      (
      IN userId INT,
      OUT user_name VARCHAR(100)
      )
      BEGIN
      SELECT username
      INTO user_name
      FROM user
      WHERE user_id = userId;
      END $$
      DELIMITER ;
  </code></pre>
  
  <p>Then there is my two php files:</p>
  
  <pre><code>    &lt;?php
      //db_config.php
      $mysqli_host = "localhost";
      $mysqli_user = "root"; //I'm not stupid enough to use this in development
      $mysqli_pass = "root"; //before anyone comments about the root usage
      $mysqli_db = "text_development";
      ?&gt;
  
  
      &lt;?php
      //index.php
      require('incl/db_config.php');
      $dbConnection = new Mysqli($mysqli_host, $mysqli_user, $mysqli_pass, $mysqli_db) or die(mysql_error());
      print '&lt;h1&gt;Stored Procedure Retrieval Test&lt;/h1&gt;';
      $id = 1;
      $return = '';
      $result = $dbConnection-&gt;query( 'CALL get_user($id,$return)');
      print $result;
      ?&gt;
  </code></pre>
  
  <p>My problem arises with the index.php page. It doesn't actually seem to return anything. When executing the stored procedure in PHPMyAdmin the username test is returned when I pass in the user id of 1 however nothing is returned to the screen when calling the function in php. I've also tried printing $return as well but this just returns an empty string (as I define in the code above). I've tried using this online tutorial but the solutions there do not seem to work :</p>
  
  <p><a href="http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/" rel="nofollow">http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/</a></p>
  
  <p>Does anyone know what I'm doing wrong here and why the return parameter of this stored procedure is not being printed to the screen? </p>