我試圖運行一個mssql存儲過程,它傳遞一些用戶輸入的數據。我直接運行存儲過程並且工作正常,但是當我嘗試使用附加的代碼運行它時,我沒有收到任何錯誤,也沒有任何更新。我認爲這與傳入的日期有關。數據庫中的日期字段被定義爲'datetime'。它可能是其他東西,但其他存儲過程在這個系統上運行相同的方式工作正常。將日期作爲輸入參數傳遞給mssql存儲過程通過PHP
//initiate function
$proc = mssql_init('usp_Update_Certificate_Customer_Details', $msdb);
//define parameters
$telId = $_POST['telId'];
$certNumber = $_POST['certNumber'];
$custTel = $_POST['main_tel'];
$instRef = $_POST['install_ref'];
//$commDate = $_POST['comm_date'];
$standards = $_POST['standards'];
$commDate = date('Y-m-d h:i:s');
echo 'telid: '.$telId.' certNumber: '.$certNumber.' custTel: '.$custTel.' instRef: '.$instRef.' commDate: '.$commDate.' standards: '.$standards;
mssql_bind($proc, '@Telephone_ID', $telId, SQLINT4, false, false, 10);
mssql_bind($proc, '@Certificate_Number', $certNumber, SQLINT4, false, false, 10);
mssql_bind($proc, '@Customer_Telephone', $custTel, SQLVARCHAR, false, false, 10);
mssql_bind($proc, '@Installers_Reference', $instRef, SQLVARCHAR, false, false, 10);
mssql_bind($proc, '@Commisioned_Date', $commDate, SQLDATETIME, false, false, 10);
mssql_bind($proc, '@Installed_to_Standards', $standards, SQLVARCHAR, false, false, 10);
//Execute Procedure
$result = mssql_execute($proc);
//Free Memory
mssql_free_statement($proc);
當我設置爲「SQLDATETIME」我得到一個PHP的警告
Warning: mssql_bind() expects parameter 4 to be long, string given
如果我設置爲「SQLVARCHAR」我沒有得到任何錯誤,但該領域運行領域運行如上沒發生在數據庫中更新
我已經在下面運行存儲過程粘貼:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Phil Yeomn
-- Create date: 19-04-2008
-- Description: Update Customer Details
-- =============================================
ALTER PROCEDURE [dbo].[usp_Update_Certificate_Customer_Details](
@Telephone_ID INT,
@Certificate_Number Int,
@Customer_Telephone Varchar(50),
@Installers_Reference Varchar(50),
@Commisioned_Date Datetime,
@Installed_To_Standards Varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
IF @Telephone_ID <> 0 AND @Customer_Telephone IS NULL
BEGIN
DELETE FROM ssaib.dbo.Telephone_T
WHERE Telephone_ID = @Telephone_ID
SET @Telephone_ID = NULL
END
IF @Telephone_ID = 0 AND @Customer_Telephone IS NOT NULL
BEGIN
INSERT INTO ssaib.dbo.Telephone_T (Telephone_Number_VC, Last_Update_DT)
VALUES (@Customer_Telephone, GETDATE())
SET @Telephone_ID = SCOPE_IDENTITY()
END
IF @Telephone_ID = 0
BEGIN
SET @Telephone_ID = NULL
END
UPDATE ssaib.dbo.Certificate_Returns_T
SET Customer_Telephone_ID = @Telephone_ID,
Installers_Reference_VC = @Installers_Reference,
Commisioned_Date_DT = @Commisioned_Date,
Installed_To_Standards_VC = @Installed_To_Standards
WHERE (Certificate_Return_ID = @Certificate_Number)
END
我在下面粘貼了完整的錯誤,第一行是傳入存儲過程的值,只是顯示爲一個字符串,以檢查它們是否全部存在。
telid: 61529 certNumber: 1262789 custTel: 01423 734002 instRef: /3548 commDate: 2012-05-05 00:00:00 standards: PD 6662 and DD 243
Warning: mssql_bind() expects parameter 4 to be long, string given in /home/ssaibuk/public_html/common/modules/supplier/certificates-direct.php on line 111
Warning: mssql_execute() [function.mssql-execute]: message: Procedure or function 'usp_Update_Certificate_Customer_Details' expects parameter '@Commisioned_Date', which was not supplied. (severity 16) in /home/ssaibuk/public_html/common/modules/supplier/certificates-direct.php on line 116
Warning: mssql_execute() [function.mssql-execute]: General SQL Server error: Check messages from the SQL Server (severity 16) in /home/ssaibuk/public_html/common/modules/supplier/certificates-direct.php on line 116
Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in /home/ssaibuk/public_html/common/modules/supplier/certificates-direct.php on line 116
我對MS SQL並不熟悉,但爲什麼您使用'SQLFLT8'作爲日期的數據類型? – 2012-07-26 13:58:17