试图从 SQL Server 2008 中的存储过程 (SP) 中获取 3 个结果集时,我有点发疯了。
存储过程:
CREATE PROCEDURE db_abbTest
AS
BEGIN
SET NOCOUNT ON;
SELECT 1
SELECT 2
SELECT 3
RETURN 0
END
GO
<?php
$serverName = "server";
$connectionInfo = array("UID"=> "user", "PWD" =>"pass", "Database"=>"sample_db");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
$sql = "db_AbbTest";
$r = sqlsrv_query($conn, $sql, null, array(
'Scrollable' => SQLSRV_CURSOR_STATIC,
'SendStreamParamsAtExec' => true
));
var_dump($r);
while( $obj = sqlsrv_fetch( $r))
{
var_dump($obj);
var_dump(sqlsrv_fetch_array($r));
}
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Close the connection. */
sqlsrv_close( $conn);
SP 返回三个结果(3x 选择语句)但是我似乎无法从查询中获取所有结果。有任何想法吗?我试过while(sqlsrv_fetch_object($r){//do something})
但没有运气..