|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-02-12 21:14 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 03:00:02 2025 UTC |
Here is the error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY010]: Function sequence error: 0 [Microsoft][ODBC Driver Manager] Function sequence error (SQLExecute[0] at ext\pdo_odbc\odbc_stmt.c:133)' in C:\Program Files\nusphere\phped\Projects\ASCPlatform\noname1.php:11 Stack trace: #0 C:\Program Files\nusphere\phped\Projects\ASCPlatform\noname1.php(11): PDOStatement->execute(Array) #1 {main} thrown in C:\Program Files\nusphere\phped\Projects\ASCPlatform\noname1.php on line 11 The only thing missing from the script is: $dbh = new PDO('odbc:peo', '11', '11');I can confirm this problem on PHP 5.2.1. The exact error is the following: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY010]: Function sequence error: 0 [Microsoft][ODBC Driver Manager] Function sequence error (SQLExecute[0] at ext\pdo_odbc\odbc_stmt.c:133)' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\iptaa\lib\IPTAA_CRUD.class.php:135 Stack trace: #0 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\iptaa\lib\IPTAA_CRUD.class.php(135): PDOStatement->execute() #1 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\iptaa\lib\IPTAA_CRUD.class.php(414): IPTAA_CRUD->create(Array) #2 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\iptaa\users.php(15): IPTAA_CRUD->handleHttpPost() #3 {main} thrown in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\iptaa\lib\IPTAA_CRUD.class.php on line 135 Fatal error: Exception thrown without a stack frame in Unknown on line 0 This is a pretty serious limitation of the PDO ODBC driver.This code illustrates the fact that SQL can work with a variety of date formats when moving to a SQL2005 type of datetime. To use this script, remove the sql comments '--' and comment out the appropriate params line to test PDO attempts to work with the different formats. All of them throw exceptions. <?php include("../include/config.inc"); $db = new bkg_db(); $query = "SELECT 'sqltest1' = CAST('20080101 12:07:32' AS datetime) ,'sqltest2' = CAST('2008-01-01 12:07:32' AS datetime) ,'sqltest3' = CAST('01/01/2008 12:07:32' AS datetime) ,'sqltest4' = CAST('01-01-2008 12:07:32' AS datetime) --,'pdotest' = CAST(:pdotest AS varchar) "; $params = array(':pdotest' => '20080101 12:07:32'); $params = array(':pdotest' => '2008-01-01 12:07:32'); $params = array(':pdotest' => '01/01/2008 12:07:32'); $params = array(':pdotest' => '01-01-2008 12:07:32'); $params = array(); $db->execute_query($query,$params); print_r($db->get_results()); ?>I am still experiencing this problem at 5.2.11 Windows XP and 2003, MS SQL Server 2005. PHP PDO, ODBC driver. I am providing a test case that meets the requirements because this issue does not appear to be resolved. <?php $activeConnection = new PDO("odbc:mssql_dev", "phpbug","phpbug"); $stmt = $activeConnection->prepare("create table phpbug (id int, dt datetime)"); $stmt->execute(); $stmt = $activeConnection->prepare("insert into phpbug (id, dt) values (:id, :dt)"); $stmt->bindValue(":id", 1, PDO::PARAM_INT); $stmt->bindValue(":dt", "01-JAN-09", PDO::PARAM_STR); // There is no PDO::PARAM_DATE if (!$stmt->execute()) print_r($stmt->errorInfo()); ?> Error: [Microsoft][ODBC Driver Manager] Function sequence error (SQLExecute[0] at ext\pdo_odbc\odbc_stmt.c:133)Hi guys, I faced to this problem some time ago when switched to odbc driver from native PDO mssql driver because have some problems with second one. After spending some time to find solution I saw that problem with datetime format - ODBC do not accept standard date format that acceptable by other PDO drivers. In insert or update queries use this format: date('Ymd'), this worked for me and I hope that be useful for others. MSSQL 2005 PHP 5.2.9