title: Executing stored procedure with IN and OUT parameters in PHP
body: <p>I want to execute a stored procedure into my PHP code, this stored procedure has an IN and an OUT parameter. The stored procedure is this:</p>
  
  <pre><code>    USE [phl_pmx]
  
  GO
  
  DECLARE @return_value int
  
  EXEC    @return_value = [dbo].[PMX_SP_RecreateSynonymsOfSourceDb]
  
                      @sourceDb = phl
  
  SELECT  'Return Value' = @return_value
  
  GO
  </code></pre>
  
  <p>And I already wrote the following code, but it keeps giving errors that he can't execute it, or he just won't show a thing.</p>
  
  <pre><code>    &lt;?php
  ini_set('display_errors',1);
  error_reporting(E_ALL);
  include_once 'DBC.php';
  $link = mssql_connect('server', 'sa', 'password');
  
  if (isset($_POST['StoredProcedure']))
  {
  
  mssql_select_db($id,$link);
  
  
  $a = new TableOutput();
  $a-&gt;getTables ("PMX_SP_RecreateSynonymsOfSourceDb","phl");
  
  mssql_close($link);
  
  
  
  }
  elseif (isset($_POST['Value']))
  {
  $query =mssql_query("UPDATE [phl].[dbo].[PMX_EXDB] set ExtraDb='phl_pmx'");
  mssql_close($link); 
  }
  
  ?&gt;
  </code></pre>
  
  <p>This is the function for it.</p>
  
  <pre><code>&lt;?php
  class TableOutput {
  
  function getTables($procname, $parameter) {
  
      $stmt = null;
      $data = null;
      $vars = null;
      $num = null;
       $con = mssql_connect('server', 'sa', 'password');
  if
      (!$con) {
          die('Could not connect: ' . mssql_error());
      }
  
      mssql_select_db("phl",$con);  
  
      $this-&gt;setStmt(mssql_init($procname, $con));
      mssql_bind($this-&gt;getStmt(), '@sourceDb', $parameter, SQLINT2, false, false);
  
      if ($rtn != 0) {
          echo ("Errors happened when executing the stored procedure");
      }
      $exec = mssql_execute($this-&gt;getStmt());
      $data = array();
      $i = 0;
      while ($row = mssql_fetch_assoc($exec)) {
          $data[++$i] = $row;
      }
  
      unset($con);
      unset($stmt);
      return $data;
  }
  
  function setStmt($a_stmt) {
      $this-&gt;stmt = $a_stmt;
  }
  
  function getStmt() {
      return $this-&gt;stmt;
  }
  
  }
  ?&gt;`
  </code></pre>
  
  <p>Does anyone know how to correct the code, because it keeps showing me the following error:</p>
  
  <p><code>Warning: mssql_execute(): stored procedure execution failed in /var/www/mssql/management/DBC.php on line 24 Warning: mssql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/mssql/management/DBC.php on line 27</code></p>