php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70729 db2_execute() should handle DateTime parameters for timestamps.
Submitted: 2015-10-16 20:27 UTC Modified: 2017-01-16 15:25 UTC
From: zippy1981 at gmail dot com Assigned: rangercairns (profile)
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.6.14 OS: PASE
Private report: No CVE-ID: None
 [2015-10-16 20:27 UTC] zippy1981 at gmail dot com
Description:
------------
If I have the prepared SQL statement INSERT INTO WEBLIB.justin(recieved_date) VALUES(?), where recieved_date is a timestamp, I cannot pass a DateTime object into it. I can however, pass it if I format it with ->format('Y-m-d H:i:s'), which is the native DB2 format. I think the driver should handle the casting from dateTime on its own.

Test script:
---------------
CREATE TABLE WEBLIB.JUSTIN(
  id INT NOT NULL
    GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)
    CONSTRAINT WEBLIB.PK_JUSTIN PRIMARY KEY,
  recieved_date TIMESTAMP NOT NULL
);

<?php
$cn = db2_connect('', '', '');

$sql = "INSERT INTO WEBLIB.justin(recieved_date) VALUES(?);";
$stmt = db2_prepare($cn, $sql);
#this line will work
db2_execute($stmt, [(new DateTime('1981-04-28'))->format('Y-m-d H:i:s')]);
# This line does not work
db2_execute($stmt, [new DateTime('2001-09-11')]);

db2_close($cn);
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-16 15:25 UTC] rangercairns@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: rangercairns
 [2017-01-16 15:25 UTC] rangercairns@php.net
No. The ibm_db2 driver has no plan to start guessing about all conversion variants of every time, timestamp, and date. This is role of language region php script (your script task).
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 14:01:29 2019 UTC