Answered Couldn't connect sqlsrv_connect with PHP 5.4.4

  • Wednesday, July 18, 2012 1:29 PM
     
     

    Hi,


    I'm trying to configure the SQL Server driver to run on PHP 5.4.4, I downloaded the package Drivers 3.0 (my SQL Server is 2008).

    I set up Apache and PHP.ini started properly, without generating any error, I set the sqlsrv_54_ts as an extension, but in my server when I try to make the connection to the database, nothing happens.

    On another computer with version 5.3 of php, the connection string works, but in this server with version 5.4, no failures in the function was informed, but does not connect to the database.

    Someone tell me what might be happening?

All Replies

  • Wednesday, July 18, 2012 2:15 PM
     
     Answered

    Hi

    This is a question with a few different answers, depending on your system...

    Please can you post the following information:

    1. Have you installed the SQL Server Native Client 2012 on your computer that's running PHP?  If so, which version?
    2. Have you checked your PHP error log - are there any messages about the SQLSRV driver?
    3. What version of Windows is PHP running on (and is it a 32 or 64 bit version)?
    4. What build of Apache do you have?  There are versions of Apache built with different compilers - it could be VC6, VC9 or VC10.  You must have a version of Apache built with either VC9 or VC10, available from http://www.apachelounge.com/download/...
    5. Which Apache PHP interface are you using?  It could be Apache ISAPI or php5_module or FastCGI - check to see if there is a section of your phpinfo() titled 'Apache' - if there is, you should have a thread-safe (TS) version of PHP.
    6. What build of PHP do you have?  This is not just the version - from phpinfo() you can get this from the settings named "PHP Extension Build" and "Architecture".
    7. Are you connecting with sqlsrv_connect() using a user name and password, or no user name and password (Windows credentials)?

    It's possible when you go through this list you will be able to solve your own problem.  Please let us know how you get on.


    Rob


  • Wednesday, August 01, 2012 12:41 PM
     
     

    Hi LADev-RP,

    We cannot help you unless you provide more information :)

    Thanks,

    Jonathan


    This posting is provided 'AS IS' with no warranties, and confers no rights.

  • Monday, September 03, 2012 3:06 PM
     
      Has Code

    I think i got nearly the same error thats why i am adding my question to this post.

    I have got a PC which is running XAMPP with PHP 5.4.4 on it its a 64bit Windows 7 PC.

    And i have got a Server which is running MS SQL 2008 R2 in 64bit (i guess) on a 2008 R2 Windows Data Center edition. 

    When i try to connect to the MSSQL Server the following msg appears.

    Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )


    1. Have you installed the SQL Server Native Client 2012 on your computer that's running PHP?  If so, which version? -- Well yes, I did install the 64bit version
    2. Have you checked your PHP error log - are there any messages about the SQLSRV driver? -- Nope
    3. What version of Windows is PHP running on (and is it a 32 or 64 bit version)? -- windows 7 64bit
    4. What build of Apache do you have?  There are versions of Apache built with different compilers - it could be VC6, VC9 or VC10.  You must have a version of Apache built with either VC9 or VC10, available from http://www.apachelounge.com/download/... -- VC9
    5. Which Apache PHP interface are you using?  It could be Apache ISAPI or php5_module or FastCGI - check to see if there is a section of your phpinfo() titled 'Apache' - if there is, you should have a thread-safe (TS) version of PHP. -- There is no section like Apache in my phpinfo. I installed xampp to install it. 
    6. What build of PHP do you have?  This is not just the version - from phpinfo() you can get this from the settings named "PHP Extension Build" and "Architecture". -- API20100525,TS,VC9
    7. Are you connecting with sqlsrv_connect() using a user name and password, or no user name and password (Windows credentials)? -- im using username+password

    What could be wrong?

  • Monday, September 03, 2012 4:44 PM
     
     

    Hi Fretful,

    Did you follow the link in the error and install the SQL Server 2012 Native Client? The PHP Driver requires it.

    Thanks,

    Jonathan



    This posting is provided 'AS IS' with no warranties, and confers no rights.

  • Monday, September 03, 2012 5:30 PM
     
     Proposed Answer

    Fretful

    Yes, Jonathan's right.  Point 1 says Native Client 2012 (64 bit is correct).  You can get it here: http://www.microsoft.com/en-us/download/details.aspx?id=29065#SNAC

    And it looks like you already have the correct driver installed - one or both of these:

    • php_sqlsrv_54_ts.dll
    • php_pdo_sqlsrv_54_ts.dll

    Rob

    • Proposed As Answer by Fretful Tuesday, September 04, 2012 7:58 AM
    •  
  • Tuesday, September 04, 2012 8:00 AM
     
     
    Thank you! After installing the Native Client 2012 64bit the connection worked! I am wondering because I downloaded the native client mentioned in the error msg but it did not work.
  • Tuesday, September 04, 2012 5:26 PM
     
     
    Thank you! After installing the Native Client 2012 64bit the connection worked! I am wondering because I downloaded the native client mentioned in the error msg but it did not work.

    Hi Fretful,

    I just followed the links and found the information is actually correct. Did you accidentally install the dependencies for the Version 2.0 driver?

    "Version 3.0 of the driver requires Microsoft SQL Server 2012 Native Client. You can download Microsoft SQL Server 2012 Native Client from the SQL Server 2012 feature pack page."

    Cheers,

    Jonathan


    This posting is provided 'AS IS' with no warranties, and confers no rights.

  • Friday, September 07, 2012 8:27 AM
     
     
    Hii this problem i have faced also during developing on php development so any one has perfect answer? so please help
  • Friday, September 07, 2012 11:07 AM
     
     Answered

    There is no perfect answer to this question, it is paradoxical.  The answers are all over this forum, all different, and all correct at the same time.

    Here is a similar question: What colour is a grape?

    Original answer edited:

    I wasn't happy with my original answer to this, so I have written a blog page with all the combinations possible from Microsoft's builds - it's still not easy to follow but might help: http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html

    Rob
  • Saturday, September 08, 2012 2:15 AM
     
     
    Great post, Robert, thanks!

    This posting is provided 'AS IS' with no warranties, and confers no rights.