我有一个从 MSSQL 数据库返回多个结果集的存储过程。我遇到的问题是遍历每个结果集。似乎 Yii 没有推进到下一个结果集来遍历行。这是一个例子:
结果 1:
TOTAL
-----
999
结果 2:
ID |NAME
---|----
0 | Jon
1 | Bob
2 | Sarah
3 | Pete
这是我在 Yii 中进行这项工作的尝试。
//create the call to stored proc
$command=parent::$db->createCommand("exec sp_showUsers");
//run the query
$dataReader = $command->query();
//For the current object assign the row to a variable
while (($row = $dataReader->read()) !== false){
//if the row has a total column
if(isset($row['total'])){
$total = $row['total'];
}
}
//Test if there is another result
$usersExist = $dataReader->nextResult();
//$dataReader->next(); - REMOVED AS NOT NEEDED
if($usersExist){
$userTable = array();
$i = 0;
while (($userRow = $dataReader->read())!== false){
//add each row to a temporary array
$userTable[$i] = $userRow['id'];
$i++;
}
}
...
->next()
即使已调用该方法,这似乎也不会遍历第二个结果集?任何帮助将不胜感激!谢谢。
Ps 存储过程确实有效,我可以使用普通 PHP 和sqlsrv_next_result()
方法循环遍历结果。