簡體   English   中英

PHP PDO中的DB2時間戳格式

[英]DB2 timestamp format in PHP PDO

我已經通過ODBC和EasySoft驅動程序使PHP與DB2(在Ubuntu 14.04上為v10.5)通信。 使用select id from new table(insert ....)格式的select id from new table(insert ....)進行查詢時,時間戳格式出現問題。

這是我的桌子:

$create = "create table permissions (
        id int not null generated always as identity,
        name varchar(255) not null,
        display_name varchar(255),
        description varchar(255),
        created_at timestamp default current_timestamp not null,
        updated_at timestamp default current_timestamp not null
      )";

$pdo->prepare($create)->execute();

效果很好,原始的PDO插入也可以:

$sth = $pdo->prepare("insert into permissions (name, display_name, description, updated_at, created_at) values (?, ?, ?, ?, ?)");
$sth->execute([
"client_admin_dashboard",
"Client Admin Dashboard",
"Can view overview of team",
"2015-07-09 14:10:50.000",
"2015-07-09 14:10:50.000"
]);

但是,如果我嘗試執行select id樣式查詢(具有相同的綁定):

$sth = $pdo->prepare("select id from new table(insert into permissions (name, display_name, description, updated_at, created_at) values (?, ?, ?, ?, ?))");

我收到以下錯誤:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: -180 
[Easysoft][ODBC-DB2 Driver][DRDA] SQL0180N  The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007 (SQLExecute[4294967116] at 
/build/php5-RvVZKb/php5-5.6.10+dfsg/ext/pdo_odbc/odbc_stmt.c:254)' in 
/home/vagrant/repos/throwaway/test.php on line 65

PDOException: SQLSTATE[22007]: Invalid datetime format: -180 [Easysoft][ODBC-DB2 Driver][DRDA] SQL0180N  
The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007 
(SQLExecute[4294967116] at /build/php5-RvVZKb/php55.6.10+dfsg/ext/pdo_odbc/odbc_stmt.c:254) in /home/vagrant/repos/throwaway/test.php
on line 65

Call Stack:
    0.0007     226848   1. {main}() /home/vagrant/repos/throwaway/test.php:0
    0.1021     230648   2. PDOStatement->execute()     /home/vagrant/repos/throwaway/test.php:65

任何幫助將非常感激!

非常感謝

編輯:

將變量移到查詢本身而不是使用綁定可以很好地工作:

$sth = $pdo->prepare("select id from new table(insert into permissions (name,
display_name, description, updated_at, created_at) values ( 
'client_admin_dashboard', 'Client Admin Dashboard', 'Can view overview of 
team', '2015-07-09 14:10:50.000', '2015-07-09 14:10:50.000'))")->execute();

真的很奇怪。 如果我嘗試從CLP靜態執行命令,則一切正常:

select id from new table(insert into permissions (name, display_name, description, updated_at, created_at) values ( 'client_admin_dashboard', 'Client Admin Dashboard', 'Can view overview of team', '2015-07-09 14:10:50.000', '2015-07-09 14:10:50.000'))

ID
-----------
          2

 1 record(s) selected.

可能是ODBC驅動程序(或區域設置)以某種方式弄亂了時間戳格式嗎? 為了確認這一點,我唯一想到的方法就是采用DB2 CLI和服務器跟蹤,它們應該顯示從客戶機接收到的時間戳數據。

附帶說明一下,我注意到在失敗的情況下, created_atupdated_at的順序是相反的:

...(insert into permissions (..., updated_at, created_at)...

一個愚蠢的問題,但是如果您定購訂單會怎樣?

驅動程序供應商發布了修復程序。 他們很難找到問題所在:

進行了一些跟蹤,因為問題僅發生在具有該確切PDO-ODBC版本的PHP版本上。 如果您使用的是.0.1版本,它不會給出相同的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM