我在使用PHP調用它時從我的Sql Server 2008存儲過程獲取結果集時出現問題。當我在sql中執行存儲過程時,我得到結果,所以我知道問題不在於存儲過程(如下所示)。 SQL存儲過程SQL存儲過程/ Php問題
USE [HRAPPS]
GO
/****** Object: StoredProcedure [dbo].[sp_GetSecurityAnswer] Script Date: 10/21/2011 08:38:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_GetSecurityAnswer]
(
@ThisContactId INT, @ThisQuestionId INT, @ThisAnswer varchar(255)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT
a.Cont_id,
a.QuestionId
FROM dbo.sec_answers a
WHERE a.cont_id = @ThisContactId and
a.QuestionId = @ThisQuestionId and
lower(a.Response) = lower(@ThisAnswer)
END
這裏是PHP代碼調用存儲過程。注意:與數據庫的連接有效,所以我知道它不是問題。
* PHP代碼*
if(!$dbCon=mssql_connect(DBHOST,DBUSER,DBPASS))
{
$error = "Unable to Connect to Database. Please Try Again Later.";
}
else
{
$stmt = mssql_init("sp_GetSecurityAnswer", $dbCon);
mssql_bind($stmt, "@ThisContactId", $_SESSION['thisContId'], SQLINT4, false, false, 6);
mssql_bind($stmt, "@ThisQuestionId", $_SESSION['SecQuestion'], SQLINT4, false, false, 2);
mssql_bind($stmt, "@ThisAnswer", $_SESSION['ThisAnswer'], SQLVARCHAR, false, false, 255);
$Security_Verification_Result = mssql_execute($stmt, false);
IF(!mssql_num_rows($Security_Verification_Result))
{
ECHO "You have Incorrectly answered your selected Security Verification Question, Please go back and try again";
EXIT();
}
ELSE
{
header("Location: some_url?userfullname=".$_SESSION['userfullname'] .'&cont_id='.$_SESSION['ThisContId']);
}
}
exit();
PHP代碼的結束
所以我缺少什麼傢伙(和加爾斯呢!)?任何幫助將不勝感激:d 由於事先
你得到了什麼輸出,你期望什麼? – ObscureRobot
小心告訴我們問題是什麼?錯誤消息,意外輸出等? – MatBailie
你是否迴應出你的'$ _ SESSION ['...']'值,以確保你實際上傳遞了與你認爲相同的值? –