I am new to the SQL server and I need to create an SP that processes certain tables and writes changes and then returns the results of these changes to me as a table-value function for PHP. I tried this:
create procedure auto_fill_teste
as
begin
DECLARE @temp_table table(qtd int);
insert into @temp_table
SELECT COUNT(*) FROM sysobjects;
insert into @temp_table
SELECT COUNT(*) FROM sysindexes;
SELECT * FROM @temp_table;
end
and in php I have the following codes
<?
class MsSQLConnection {
protected $MSconn;
protected $serverName = 'localhost';
protected $connectionOptions = array("Database" => "master", "UID" => "as", "PWD" => "123456");
public $query;
function conecta_MSSQL() {
$this->MSconn = sqlsrv_connect($this->serverName, $this->connectionOptions);
if (!$this->MSconn) {
var_dump(sqlsrv_errors());
die;
}
}
function executar($sql,$params = array(),$options = array("Scrollable" => "buffered")) {
if (!$this->MSconn) {
$this->conecta_MSSQL();
}
$this->query=sqlsrv_prepare($this->MSconn, $sql, $params, $options);
sqlsrv_execute( $this->query );
}
function arrayx($a = null) {
if (empty($a))
$a = $this->query;
return sqlsrv_fetch_array($a, SQLSRV_FETCH_BOTH);
}
}
$conexao = new MsSQLConnection();
$conexao->conecta_MSSQL();
$conexao->executar("Exec dbo.auto_fill_teste");
while($row = $conexao->arrayx(NULL)){
print_r("$row <br>");
}
?>
However nothing returned; if I run the command in the manager studio it returns the resultset of temp_table as expected.