#40452 [Opn->Fbk]: ODBC and SQL Server datetime parameter fields fail on insert
| From: | tony2001@php.net | Date: | Mon, 12 Feb 2007 21:54:51 +0000 |
| Subject: | #40452 [Opn->Fbk]: ODBC and SQL Server datetime parameter fields fail on insert | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-108765@lists.php.net to get a copy of this message | ||
ID: 40452
Updated by: tony2001@php.net
Reported By: aspen dot olmsted at alliance dot biz
-Status: Open
+Status: Feedback
Bug Type: PDO related
Operating System: Windows 2003, XP
PHP Version: 5.2.1
New Comment:
But you forgot the error itself.
And I would appreciate if you include a working script, too.
Previous Comments:
------------------------------------------------------------------------
[2007-02-12 21:43:30] aspen dot olmsted at alliance dot biz
I included a small script in the reproduce code?
------------------------------------------------------------------------
[2007-02-12 21:27:50] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2007-02-12 21:14:34] aspen dot olmsted at alliance dot biz
Description:
------------
If you have MS SQL datetime field using odbc and try to use
parameterized inserts you get a sql sequence error.
Reproduce code:
---------------
Here is sql to create table
CREATE TABLE [ASC_EventPreSale] (
[apsEventCode] [int] NOT NULL CONSTRAINT
[DF_ASC_EventPreSale_apsEventCode] DEFAULT (0),
[apsStartDate] [datetime] NOT NULL CONSTRAINT
[DF_ASC_EventPreSale_apsStartDate] DEFAULT (getdate()),
[apsFinishDate] [datetime] NOT NULL CONSTRAINT
[DF_ASC_EventPreSale_apsFinishDate] DEFAULT (getdate()),
[apsGeneralPublicDate] [datetime] NOT NULL CONSTRAINT
[DF_ASC_EventPreSale_apsGeneralPublicDate] DEFAULT (getdate()),
CONSTRAINT [PK_ASC_EventPreSale] PRIMARY KEY CLUSTERED
(
[apsEventCode]
) ON [PRIMARY]
) ON [PRIMARY]
GO
Here is php
<?php
$sql ="INSERT INTO ASC_EventPreSale
(apsEventCode,apsStartDate,apsFinishDate,apsGeneralPublicDate) VALUES
(:apsEventCode,:apsStartDate,:apsFinishDate,:apsGeneralPublicDate)";
$avalues['apsEventCode'] = 6339;
$avalues['apsStartDate'] = '2007-02-12 14:5';
$avalues['apsFinishDate'] = '2007-02-12 16:5';
$avalues['apsGeneralPublicDate'] = '2007-02-15 14:5';
$stmt=$dbh->prepare($sql);
$stmt->execute($avalues);
?>
Expected result:
----------------
If you change the field types to varchar it works fine. It should
function the same with date time fields
Actual result:
--------------
SQL Error
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40452&edit=1