php-php execution of stored procedures does not return data set problems correctly

Source: Internet
Author: User
Keywords PHP Storage Database
PHP Storage Database

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

请高手帮忙解答!谢谢!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.