0

I am not able to get the output from Stored Procedure in PHP. My variable $value does not change. I have set attribute bind to PARAM_INPUT_OUTPUT. Correct response is int from the procedure.

SQL code inside the procedure runs correctly. What is wrong?

My environment:

  • PHP 7.0.15
  • FreeTDS 0.91
  • MSSQL 2012 SP1

SQL Procedure:

DECLARE @Aaa int

EXECUTE [sp_insert_org] 
@Aaa = @Aaa OUTPUT

SELECT  @Aaa

PHP Code:

$value = 'hello';

$sth = $db->prepare($sql);
$sth->bindParam(1, $value, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4); 
$sth->execute();

var_export($value);

Result:

'hello'
Sunil
  • 3,404
  • 10
  • 23
  • 31
Tomas T.
  • 1
  • 1
  • After `$sth->execute()`, can you add `$sth->closeCursor()` and try to echo the variable? – Mjh May 10 '17 at 10:31
  • After add function closeCursor() is this same result *hello*. – Tomas T. May 10 '17 at 10:45
  • Try to refer to [this question](http://stackoverflow.com/questions/9982466/executing-a-stored-procedure-with-pdo-sqlsrv), it might help. The answer that works uses `$sth->fetch()` before echoing out the variable. – Mjh May 10 '17 at 10:47
  • you should also always put "set nocount on" as the first statement in every stored procedure in sql server. Not that it will fix this problem but it is a best practice – GuidoG May 10 '17 at 10:48
  • Really did not fix it, but thanks. – Tomas T. May 10 '17 at 10:59

0 Answers0