Laravel调用MSSQL存储过程,它返回多个记录集

时间:2018-05-20 15:25:22

标签: php laravel

我用参数调用MSsql数据库,然后返回3个左右的记录集。例如。

AS
BEGIN
    select 'record set one' as res
    select 'record set two' as res
    select 'record set three' as res
END

我正在调用存储过程的控制器如下:

$data = DB::statement("EXEC usp_StoredProcedure ?,?,?", [$a,$b,$tb]);

如何遍历所有记录集?

1 个答案:

答案 0 :(得分:0)

$conn = DB::connection('DBconnection');
$sql = "exec usp_getresults @param1=".$paramone.", @param2=".$paramtwo;
$pdo = $conn->getPdo()->prepare($sql);
$pdo->execute();
        // Setup output results
$rows = array();
$res = array();
        // Iterate through the recordsets
do {
      $rows = $pdo->fetchAll();
      array_push($res,$rows);
 } while ($pdo->nextRowset());
        // Output
return  $res;