A stored procedure is built:
Create procedure T_sp
@X int,
@y int
As
IF OBJECT_ID('TEMPEB.#DATA') IS NOT NULL DROP TABLE #DATACREATE TABLE #DATA(X INT,Y INT)INSERT INTO #DATA(X,Y) VALUES(@X,@Y)SELECT * FROM #DATA
GO
Use the following PHP code to return the data set that the stored procedure executes:
$serverName = "127.0.0.1"; ServerName\InstanceName
$connectionInfo = Array ("Database" = "Bandaiqce", "UID" = "sa", "PWD" = "Justgo");
$lik = Sqlsrv_connect ($serverName, $connectionInfo);
if (! $lik) {
echo "Connection could not being established.
";
Die (Print_r (Sqlsrv_errors (), true));
}
echo "
"." $serverName ";
//-----------------------------------------------------------------------
$sql = "{call T_SP (?,?)}";
$X = 100;
$Y = 80;
$params = Array (
Array (& $X, sqlsrv_param_in),
Array (& $Y, sqlsrv_param_in)
);
$options = Array ("scrollable" = Sqlsrv_cursor_keyset);
$stmt = sqlsrv_query ($lik, $sql, $params);
if (! $stmt) {
Die (Print_r (Sqlsrv_errors (), true));
}
$row _count = sqlsrv_num_rows ($stmt);
if ($row_count === false) echo "Error in retrieveing row count.";else ECHO "
".$row_count."
";
$serverName = "127.0.0.1"; //serverName\instanceName
$connectionInfo = array( "Database"=>"BandaiQCE", "UID"=>"sa", "PWD"=>"justgo");
$lik = sqlsrv_connect( $serverName, $connectionInfo);
if( !$lik ) {
echo "Connection could not be established.
";
die( print_r( sqlsrv_errors(), true));
}
echo "
"."$serverName";
//-----------------------------------------------------------------------
$sql = "{call T_SP (?,?)}";
$X = 100;
$Y = 80;
$params = array(
array(&$X, SQLSRV_PARAM_IN),
array(&$Y, SQLSRV_PARAM_IN)
);
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $lik, $sql, $params, $options);
if( !$stmt ) {
die( print_r( sqlsrv_errors(), true));
}
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count === false) echo "Error in retrieveing row count.";else ECHO "
".$row_count."
";
?>
执行结果报如下错误:
Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 16954 [code] => 16954 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]正在直接执行 SQL;无游标。 [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]正在直接执行 SQL;无游标。 ) )
很明显:错误的原因在于存储过程执行的问题,为何未能返回数据集?也就是为何没有按预期返回如下结果?
X Y
100 80
请高手帮忙解答!谢谢!