php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74626 PDO ODbC does not paramaterize datetimeoffset in Microsoft SqlServer right
Submitted: 2017-05-22 02:33 UTC Modified: -
From: zippy1981 at gmail dot com Assigned:
Status: Open Package: PDO ODBC
PHP Version: 7.1.5 OS: Windows 10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-05-22 02:33 UTC] zippy1981 at gmail dot com
Description:
------------
Lets say I have the following temp table defined:

DROP TABLE IF EXISTS #dateTable;
CREATE TABLE #dateTable (
	Id INT NOT NULL PRIMARY KEY CLUSTERED IDENTITY (1,1),
	[timestamp] DATETIMEOFFSET NOT NULL,
	message NVARCHAR(255) NOT NULL
);

And I have an odbc pdo connection $this->cn.

I can insert a row with
        $sql = <<< EOSQL
INSERT INTO #dateTable (message, [timestamp]) VALUES (
		'Solid string insert.',
		'%s'
	);
EOSQL;
$this->cn->exec(sprintf($sql);


However, if I paramaterize it like so:

        $sql = <<< EOSQL
INSERT INTO #dateTable (message, [timestamp]) VALUES (
		'Solid string insert.',
		:timestamp
	);
EOSQL;

        $stmt = $this->cn->prepare($sql);

None of the following options work:


1. 
    $stmt->execute([date(DATE_ATOM)]);
2.
    $timestamp = date(DATE_ATOM);
    $stmt->bindParam(':timestamp', $timestamp);
    $result = $stmt->execute();
3.
    $stmt->bindValue(':timestamp', date(DATE_ATOM));
    $result = $stmt->execute();

However, if I do PDO with the SqlSvr driver it works just fine.

Test script:
---------------
https://github.com/zippy1981/PhpSqlServerDateTime

Actual result:
--------------
PDOException: SQLSTATE[22018]: Invalid character value for cast specification: 206 [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Operand type clash: text is incompatible with datetimeoffset (SQLExecute[206] at ext\pdo_odbc\odbc_stmt.c:260)

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC