locked
We need a PDO::ATTR_DATE_STRING attribute for the PDO driver RRS feed

  • Question

  • Hello,

    I'm glad to see that PDO support will be added in 2.0 but I would also like to see an attribute that allows date fields to be returned as strings and not as DateObjects. This will make things easier when converting from another database that returns date columns as strings.

    The attribue could be called PDO::ATTR_STRINGIFY_DATE_FETCHES or  PDO::ATTR_DATE_STRING

     

     

    Monday, July 26, 2010 3:58 PM

Answers

  • Hello xwisdom,

    While the SQLSRV driver defaults to DateTime objects and provides the developer the option to receive them as strings using the ReturnDatesAsStrings connection option, we are responding to the feedback received for the PDO_SQLSRV driver to default to strings for datetime.

    Per our documentation for ReturnDatesAsStrings, we note the following: "When using the PDO extension, dates are returned as strings. PDO has no datetime type."

    As we've said in a previous response to your blog comment of keeping with the "traditional PDO design", we did our best to work within the guidelines, intent and prevailing precedents. By returning datetime as strings by default, we feel we've achieved the goal of meeting the needs without extending PDO with a custom driver attribute.

    Question is: do you want/need them to be returned as objects by our PDO_SQLSRV driver?

    We are NOT changing the default for the SQLSRV driver as this is a breaking change for those that depend on this default.


    Ashay Chaudhary
    SQL Server Driver for PHP (http://blogs.msdn.com/sqlphp)
    All information provided "as-is" and without warranty.
    Monday, July 26, 2010 6:01 PM

All replies

  • Hello xwisdom,

    While the SQLSRV driver defaults to DateTime objects and provides the developer the option to receive them as strings using the ReturnDatesAsStrings connection option, we are responding to the feedback received for the PDO_SQLSRV driver to default to strings for datetime.

    Per our documentation for ReturnDatesAsStrings, we note the following: "When using the PDO extension, dates are returned as strings. PDO has no datetime type."

    As we've said in a previous response to your blog comment of keeping with the "traditional PDO design", we did our best to work within the guidelines, intent and prevailing precedents. By returning datetime as strings by default, we feel we've achieved the goal of meeting the needs without extending PDO with a custom driver attribute.

    Question is: do you want/need them to be returned as objects by our PDO_SQLSRV driver?

    We are NOT changing the default for the SQLSRV driver as this is a breaking change for those that depend on this default.


    Ashay Chaudhary
    SQL Server Driver for PHP (http://blogs.msdn.com/sqlphp)
    All information provided "as-is" and without warranty.
    Monday, July 26, 2010 6:01 PM
  • Hi Ashay,

    Thanks for the reply.

    I've just learnt that it's returned as a string by default and that's ok with me :)

    Keep up the good work.

    Monday, July 26, 2010 9:42 PM
  • Hello, Ashay:

    Question is: do you want/need them to be returned as objects by our PDO_SQLSRV driver?

    I certainly want expanded PDO types. Better debugging and transaction control wouldn't hurt, either.

    But, as you mention, these are limitations of PDO, not your driver.

    The people behind PDO are aware of its limitations. See RFC: PDO version 1 improvements .

    I think the PHP community needs to pressure the PDO developers to roll out key improvements.

    But for now, Microsoft is taking the right tack by working "within the guidelines, intent and prevailing precedents" of PDO.

    When PDO improves, the SQL Server PDO extension can improve with it.

    -Ken

     

     

    Wednesday, July 28, 2010 4:39 PM