Zend Framework

Sqlsrv adapter fetches certain column types as PHP Objects, not strings

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: N/A N/A
  • Resolution: Not an Issue
  • Affects Version/s: 1.9.0
  • Fix Version/s: None
  • Component/s: Zend_Db
  • Labels:
    None

Description

I have reported this issue to Juokaz but his fix (if any) didn't make it into 1.9.0

As http://msdn.microsoft.com/en-us/library/cc296193%28SQL.90%29.aspx states, certain SQL types will be converted to native PHP objects. For example, the datetime SQL time comes back as a PHP DateTime object (http://uk3.php.net/manual/en/class.datetime.php) rather than a string.

I believe that these columns should be fetched as strings, allowing you to switch between the sqlsrv and other (e.g. pdo_mssql) adapters without introducing additional logic to handle string/Datetime data types in your application.

The PHP data type used to represent a column can be specified using sqlsrv_get_field. See http://msdn.microsoft.com/en-us/library/cc296208%28SQL.90%29.aspx

Activity

Hide
Juozas Kaziukenas added a comment -

I have few sollutions in mind, but only one work for me: having Date object cast to sting. Its quite easy in all calls to check if returned value is date object and then return value as a string representation.
I don't think that using sqlsrv_get_field for all fields is a good idea. Basically you will end-up with exponentially increasing load.

Show
Juozas Kaziukenas added a comment - I have few sollutions in mind, but only one work for me: having Date object cast to sting. Its quite easy in all calls to check if returned value is date object and then return value as a string representation. I don't think that using sqlsrv_get_field for all fields is a good idea. Basically you will end-up with exponentially increasing load.
Hide
David Caunt added a comment -

I agree Juozas, I think this is the most efficient way to handle the problem. The overhead in building a string from the DateTime should be minimal.

Many thanks

Show
David Caunt added a comment - I agree Juozas, I think this is the most efficient way to handle the problem. The overhead in building a string from the DateTime should be minimal. Many thanks
Hide
Karl Southern added a comment -

It might be worth noting that with the very recent Sqlsrv 1.1 CTP there is now an option to return all datetime values as strings, which you can pass into the driver_options of your DB config

http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/42503986-b14b-4301-b142-96f8275ebc7a

http://msdn.microsoft.com/en-us/library/ee376928%28SQL.90%29.aspx

Show
Karl Southern added a comment - It might be worth noting that with the very recent Sqlsrv 1.1 CTP there is now an option to return all datetime values as strings, which you can pass into the driver_options of your DB config http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/42503986-b14b-4301-b142-96f8275ebc7a http://msdn.microsoft.com/en-us/library/ee376928%28SQL.90%29.aspx
Hide
David Caunt added a comment -

Excellent. I wonder if this option should be enabled by default, so this adapter functions as per other Zend_Db_Adapters?

In testing the 1.1 version, I was required to update my SQL Server Native Client component. The link given in the exception was wrong (outdated), however and I found the latest version at http://go.microsoft.com/fwlink/?LinkId=123717&clcid=0x409 via http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c6c3e9ef-ba29-4a43-8d69-a2bed18fe73c

Show
David Caunt added a comment - Excellent. I wonder if this option should be enabled by default, so this adapter functions as per other Zend_Db_Adapters? In testing the 1.1 version, I was required to update my SQL Server Native Client component. The link given in the exception was wrong (outdated), however and I found the latest version at http://go.microsoft.com/fwlink/?LinkId=123717&clcid=0x409 via http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c6c3e9ef-ba29-4a43-8d69-a2bed18fe73c
Hide
Ralph Schindler added a comment -

This has been fixed at the driver level by Microsoft in later versions of their sqlsrv driver. It is sugguested you upgrade to 1.1 of the sql server driver.

-ralph

Show
Ralph Schindler added a comment - This has been fixed at the driver level by Microsoft in later versions of their sqlsrv driver. It is sugguested you upgrade to 1.1 of the sql server driver. -ralph

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: