Blog

Thoughts, views, rants. You know the drill.

On the off chance you're intending to do any development with using SqlSrv and ZF, I'd suggest taking a cursory look at ZF-7431 before hand. Equally if you're planning on doing any dev with Sqlsrv and plan to migrate to other SQL platforms later, then it could be just as helpful.

The fact that SqlSrv will return PHP objects is rather nice, unless you already have existing code that assumes strings are returned, like almost all other database extensions available for PHP. The easiest "fix" to allow your code to work across as many systems as possible is to ensure that you pass in ReturnDatesAsStrings as an option.

  • Renaud Oct 06, 2009 Reply
    Renaud's gravatar

    Hi and thanks for the tip.
    Just one question, how do you setup this option in your application.ini (or in your ZF bootstrap) ?

    Thanks in advance
    --
    Renaud

  • the_angry_angel Oct 06, 2009 Reply
    the_angry_angel's gravatar

    We have the following in our config (we use Zend_Config_Ini, you'll need to modify if you use something different) -

    db.adapter=Sqlsrv
    db.host=localhost
    db.driver_options.ReturnDatesAsStrings=true

    Which is then passed into the Zend_Db factory as follows -

    $db = Zend_Db::factory($config->db->adapter, $config->db->toArray());

    Hope that helps!

  • Declan Oct 12, 2009 Reply
    Declan's gravatar

    Hi,

    I'm using the Sqlsrv adapter with version 1.0 of the PHP driver.

    I need to be able to insert a date in format dd/mm/yyyy into a sql server datetime column. If I update to v1.1 of the driver and set the ReturnsDatesAsStrings is it possible to send the date as a string when calling insert

  • the_angry_angel Oct 12, 2009 Reply
    the_angry_angel's gravatar

    Provided that the server is setup to receive dates in the dd/mm/yyyy format (you can override on a per-connection basis by using SET DATEFORMAT DMY if necessary - I do this on one or two servers where its not possible to alter the locale settings), yes, the SqlSrv 1.1 CTP does allow you to insert datetimes as strings :)

    However it's probably a better idea, if you can, to insert and extract from SQL in ISO format, and then convert as necessary using Zend_Date for display and from user input. I've found that by doing so I have a lot fewer problems when it comes down to it at the end of the day. Of course, that's your choice.

  • theangryangel.co.uk Oct 13, 2009 Reply
    theangryangel.co.uk's gravatar
  • truongvc Oct 25, 2009 Reply
    truongvc's gravatar

    Hi !
    Your suggestion is so amazing and
    I'm trying to using sqlsrv with MSSQL 2000 but it doesnt work. I try another Adapter and It works with PDO_MSSQL. But It still have some problems with UTF-8 field of MSSQL 2000. It cant display correct UTF-8 format.
    Do you have any exprience with MSSQL 2000 + Zend Framework ? Could you help me solve this problem.
    Thank alot.

  • the_angry_angel Oct 25, 2009 Reply
    the_angry_angel's gravatar

    Unfortunately the SqlSrv extension only works with 2005 and up :(

    Provided that your page is being served as UTF-8 (with a meta tag, or other solution - http://developers.sun.com/global/technology/standards/reference/faqs/how-to-utf-8.html might help), and the text is stored properly in SQL (note, that MSSQL's support for UTF-8 is a bit iffy and it doesn't actually store it as UTF-8 - see http://support.microsoft.com/kb/232580), it should be pulled and displayed with no trouble using PDO_MSSQL or any of the other extensions - at least in my experience. However, I will admit that it's rather limited.

    Edit: You might find the following link useful if you're running a mixed setup interestingly - http://www.iezzi.ch/archives/371

  • Tina Jan 27, 2012 Reply
    Tina's gravatar

    Thanks for the insight. It bnrigs light into the dark!