title: How to capture T-SQL output generated by print statement with PHP ODBC client?
body: <p>I have a stored procedure that is returning its result using a transact <code>print</code> statement to return it's result.</p>
  
  <p>Until now I used the <code>php_mssql</code> extension and its <code>mssql_get_last_message()</code> function to get the returned text.</p>
  
  <p>As PHP has dropped the support for the mssql extension, I decided to fall back to the <code>php_odbc</code> extension.</p>
  
  <p>The problem I face is that I cannot capture the info using <code>odbc_errormsg()</code>. Is there a way to retrieve the print message using PHP and ODBC ?</p>
  
  <p>I found some interesting questions dealing with the subject of <code>print</code> and <code>odbc</code>, but none related to PHP.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/268384/print-statement-in-t-sql">PRINT statement in T-SQL</a></li>
  <li><a href="https://stackoverflow.com/questions/8689336/how-can-i-display-the-output-of-sql-print-command-in-c">How Can i display the output of SQL “PRINT” Command in C#?</a></li>
  </ul>
  
  <p>PHP code with mssql (works):</p>
  
  <pre><code>$query = "exec dbo.PdaBLCreer 12345";
  $res = mssql_query($query);
  $message = mssql_get_last_message();
  </code></pre>
  
  <p>PHP code with odbc (does not work, $message is always empty):</p>
  
  <pre><code>$query = "exec dbo.PdaBLCreer 12345";
  $res = odbc_exec($connection, $query);
  $message = odbc_errormsg($connection);
  </code></pre>
  
  <p>T-SQL stored procedure</p>
  
  <pre><code>CREATE PROCEDURE dbo.PdaBLCreer
      @iArgument int
  AS
  BEGIN
      ...
      PRINT @vNr
      RETURN @vNr
  END
  </code></pre>