Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 3.99 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Passing date as input parameter to mssql stored procedure through PHP
  2. //initiate function
  3.     $proc = mssql_init('usp_Update_Certificate_Customer_Details', $msdb);
  4.  
  5.     //define parameters
  6.     $telId = $_POST['telId'];
  7.     $certNumber = $_POST['certNumber'];
  8.     $custTel = $_POST['main_tel'];
  9.     $instRef = $_POST['install_ref'];
  10.     //$commDate = $_POST['comm_date'];
  11.     $standards = $_POST['standards'];
  12.     $commDate = date('Y-m-d h:i:s');
  13.     echo 'telid: '.$telId.' certNumber: '.$certNumber.' custTel: '.$custTel.' instRef: '.$instRef.' commDate: '.$commDate.' standards: '.$standards;
  14.     mssql_bind($proc, '@Telephone_ID', $telId, SQLINT4, false, false, 10);
  15.     mssql_bind($proc, '@Certificate_Number', $certNumber, SQLINT4, false, false, 10);
  16.     mssql_bind($proc, '@Customer_Telephone', $custTel, SQLVARCHAR, false, false, 10);
  17.     mssql_bind($proc, '@Installers_Reference', $instRef, SQLVARCHAR, false, false, 10);
  18.     mssql_bind($proc, '@Commisioned_Date', $commDate, SQLDATETIME, false, false, 10);
  19.     mssql_bind($proc, '@Installed_to_Standards', $standards, SQLVARCHAR, false, false, 10);
  20.  
  21.     //Execute Procedure
  22.     $result = mssql_execute($proc);
  23.  
  24.     //Free Memory
  25.     mssql_free_statement($proc);
  26.        
  27. Warning: mssql_bind() expects parameter 4 to be long, string given
  28.        
  29. SET ANSI_NULLS ON
  30.  
  31. GO
  32.  
  33. SET QUOTED_IDENTIFIER ON
  34.  
  35. GO
  36.  
  37. -- =============================================
  38.  
  39. -- Author:        Phil Yeomn
  40.  
  41. -- Create date: 19-04-2008
  42.  
  43. -- Description:   Update Customer Details
  44.  
  45. -- =============================================
  46.  
  47. ALTER PROCEDURE [dbo].[usp_Update_Certificate_Customer_Details](
  48.  
  49. @Telephone_ID INT,
  50.  
  51. @Certificate_Number Int,
  52.  
  53. @Customer_Telephone Varchar(50),
  54.  
  55. @Installers_Reference Varchar(50),
  56.  
  57. @Commisioned_Date Datetime,
  58.  
  59. @Installed_To_Standards Varchar(50)
  60.  
  61. )
  62.  
  63.  
  64.  
  65. AS
  66.  
  67. BEGIN
  68.  
  69. SET NOCOUNT ON;
  70.  
  71.  
  72.  
  73. IF @Telephone_ID <> 0 AND @Customer_Telephone IS NULL
  74.  
  75. BEGIN
  76.  
  77.       DELETE FROM ssaib.dbo.Telephone_T
  78.  
  79.       WHERE Telephone_ID = @Telephone_ID
  80.  
  81.  
  82.  
  83.       SET @Telephone_ID = NULL
  84.  
  85. END
  86.  
  87.  
  88.  
  89. IF @Telephone_ID = 0 AND @Customer_Telephone IS NOT NULL
  90.  
  91. BEGIN
  92.  
  93. INSERT INTO       ssaib.dbo.Telephone_T (Telephone_Number_VC, Last_Update_DT)
  94.  
  95. VALUES               (@Customer_Telephone, GETDATE())
  96.  
  97.  
  98.  
  99. SET @Telephone_ID = SCOPE_IDENTITY()
  100.  
  101. END
  102.  
  103.  
  104.  
  105. IF @Telephone_ID = 0
  106.  
  107. BEGIN
  108.  
  109. SET @Telephone_ID = NULL
  110.  
  111. END
  112.  
  113.  
  114.  
  115. UPDATE      ssaib.dbo.Certificate_Returns_T
  116.  
  117. SET         Customer_Telephone_ID = @Telephone_ID,
  118.  
  119.             Installers_Reference_VC = @Installers_Reference,
  120.  
  121.             Commisioned_Date_DT = @Commisioned_Date,
  122.  
  123.             Installed_To_Standards_VC = @Installed_To_Standards
  124.  
  125. WHERE  (Certificate_Return_ID = @Certificate_Number)
  126.  
  127.  
  128.  
  129.  
  130.  
  131. END
  132.        
  133. telid: 61529 certNumber: 1262789 custTel: 01423 734002 instRef: /3548 commDate: 2012-05-05 00:00:00 standards: PD 6662 and DD 243
  134. 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
  135.  
  136. 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
  137.  
  138. 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
  139.  
  140. Warning: mssql_execute() [function.mssql-execute]: stored procedure execution failed in /home/ssaibuk/public_html/common/modules/supplier/certificates-direct.php on line 116
  141.        
  142. CREATE PROCEDURE [dbo].[WorkingWithDateObjects]
  143. -- Add the parameters for the stored procedure here
  144.  
  145. @dateString [varchar] (19) = null, -- ex: '2009-07-01 00:00:00.000'
  146. @dateObject [datetime] = null -- computed in sp from @dateString
  147.  
  148. AS
  149.  
  150. BEGIN
  151. SET NOCOUNT ON;
  152. SET @dateObject = CONVERT(VARCHAR(19),@dateString,120)
  153.  
  154.     SELECT *
  155.  
  156.     FROM SomeTable
  157.  
  158.     WHERE DateField >= @dateObject
  159.  
  160.   END
  161.        
  162. $commDate = date('Y-m-d H:i:s');