我创建了一个microsoft sql存储过程,我从下面的php代码调用它。我没有得到任何错误,但我也没有得到任何输出。我已经看了一遍,但我仍然模糊如何做WHILE语句从sql检索我需要的变量...我希望有人可以看看下面的PHP代码(和下面的SQL代码)看看我可能会缺少什么。哦,当我通过SQL执行存储过程时,它工作正常并返回我期望的数据。谢谢!
<?php
$serverName = "PRATHIBA-PC\SQL2008";
$connectionInfo = array( "Database"=>"TMS", "UID"=>"sa", "PWD"=>"asset12345" );
//$connectionInfo = array( "Database"=>"TMS");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Define the Transact-SQL query. Use question marks (?) in
place of the parameters to be passed to the stored procedure
*/
$tsql_callSP = "{call Getstudentname( 1 )}";
$studentid = '1';
$params = array(
array($studentid, SQLSRV_PARAM_IN)
);
/* Execute the query. */
$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
if( $stmt3 === false ) {
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true)); }
/* Display the value of the output parameters. */
while (sqlsrv_fetch_object($stmt3)) {
// SET PARAMETERS - SET TERMS
//echo $term;
}
/*Free the statement and connection resources. */
while ($obj=sqlsrv_fetch_object($stmt3)) {
// SET PARAMETERS - SET TERMS
echo $obj->term;}
sqlsrv_free_stmt( $stmt3);
?>
这是SQL Server存储过程代码
USE [TMS]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[Getstudentname]
SELECT 'Return Value' = @return_value
GO
当我运行此代码时,我得到输出:
exec Getstudentname 1;
这是我在sql server
中的输出1 Vivek Johari vivek@abc.com
请帮帮我们..
答案 0 :(得分:0)
您可以尝试使用问号作为参数的占位符,如下所示:
$tsql_callSP = "{call Getstudentname(?)}";
不确定这是否有帮助?