none
php no mssql. Couldn't connect sqlsrv_connect with PHP 5.4.5

    Question

  • Good morning,

    I have installed Windows 2008 Server with IIS 7.5 and PHP Version 5.4.5. This compiled with VC9. On this server I have also installed Sharepoint connecting to SQL Server 2008 on another server.

    I have to connect to a database on another server, which is in SQL Server 2000.

    In the code I had connected with mssql in php, but I think it is no longer in use and replaced by sqlsrv.

    I downloaded the dll and I put in php.ini. The extension_dir path I have it right.

    For the connection does not work, the browser tells me:
    "PHP Fatal error: Call to undefined function sqlsrv_connect () in ...."

    What can be happening?

    thanks
    Tuesday, July 24, 2012 8:44 AM

Answers

  • That error indicates that the sqlsrv extension was not successfully loaded. You can double check this by looking at the output of phpinfo(). Since you are running PHP 5.4, you should make sure that you are using the php_sqlsrv_54_nts.dll driver file. More information here: http://msdn.microsoft.com/en-us/library/cc296173(SQL.105).aspx

    -Brian


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan

    Tuesday, July 24, 2012 7:00 PM
    Moderator

All replies

  • That error indicates that the sqlsrv extension was not successfully loaded. You can double check this by looking at the output of phpinfo(). Since you are running PHP 5.4, you should make sure that you are using the php_sqlsrv_54_nts.dll driver file. More information here: http://msdn.microsoft.com/en-us/library/cc296173(SQL.105).aspx

    -Brian


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan

    Tuesday, July 24, 2012 7:00 PM
    Moderator
  • That error indicates that the sqlsrv extension was not successfully loaded. You can double check this by looking at the output of phpinfo(). Since you are running PHP 5.4, you should make sure that you are using the php_sqlsrv_54_nts.dll driver file. More information here: http://msdn.microsoft.com/en-us/library/cc296173(SQL.105).aspx

    -Brian


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan

    Hi,

    Have it in php.ini

    extension=php_sqlsrv_54_nts.dll

    phpinfo() shows nothing. ADOdb library for PHP by http://phplens.com says "mssqlnative extension not installed"

    Any suggestions on a next step?

    Installed SQLSRV30.EXE, php-5.4.5-nts-Win32-VC9-x86 on Win 2008 Ent R2 64 bit

    PHP is configured using http://www.php.net/manual/en/install.windows.iis7.php

    Cheers,

    Igor



    Friday, August 10, 2012 11:57 AM
  • I have » Microsoft 2008 C++ Runtime (x64) installed. Is it correct?

    Also phpinfo() shows:

    cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"

    Is this how its is supposed to be?

    Thank you

    Friday, August 10, 2012 12:18 PM
  • Installed sqlncli.msi - Microsoft SQL Server 2012 Native Client. No change.

    Can you guys tell what is this last column about? 


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.

    Friday, August 10, 2012 1:10 PM
  • PHP comes in two flavors: thread safe (php5ts.dll) and non-thread-safe (php5.dll). If you have a thread-safe version of PHP installed and a non-thread-safe version of the driver installed, that would explain why it won't load. Look in your PHP installation directory and see which .dll file you have, or look at the value of "Thread Safety" in the output of phpinfo().

    -Brian 


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan

    Friday, August 10, 2012 3:15 PM
    Moderator
  • PHP comes in two flavors: thread safe (php5ts.dll) and non-thread-safe (php5.dll). If you have a thread-safe version of PHP installed and a non-thread-safe version of the driver installed, that would explain why it won't load. Look in your PHP installation directory and see which .dll file you have, or look at the value of "Thread Safety" in the output of phpinfo().

    -Brian 


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan

    Thank you.

    On old versions of IIS it showed error messages about not being able to load a module. Not sure how it works now. I checked Event Log for IIS - no problems logged there too.

    I have php-5.4.5-nts-Win32-VC9-x86 installed (mentioned it in my first post) which is non-thread-safe and, as I understand, this is recommended with IIS/FastCGI and I have php5.dll in C:\PHP.

    phpinfo() -Thread safety - disabled

    In my php.ini I put both:

    extension=php_sqlsrv_54_nts.dll
    extension=php_pdo_sqlsrv_54_nts.dll

    Originally was just:

    extension=php_sqlsrv_54_nts.dll

    Another interesting twist is - I have C:\tmp as error log dir and all logging features are inables - E_ALL, display_errors etc. however when I make syntax error I see it on a page but error log is not appearing in C:\tmp. I gave IUSR all rights on it and later added Eveyone but error log is not getting created.


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.

    Saturday, August 11, 2012 3:29 AM
  • Missing error log file lead me to phpinfo() and I found that location of php.ini shown is C:\Windows.

    I tried to:

    %windir%\system32\inetsrv\appcmd.exe set config  -section:system.webServer/fastCgi ^
    /+"[fullPath='C:\php\php.exe',arguments=''].environmentVariables.^
    [name='PHPRC',value='C:\php\']" /commit:apphost

    but it returns error. I moved php.ini to C:\Windows and did iisreset however phpinfo() shows nothing in "Loaded Configuration File"

    So the problem is actually in making php.ini visible to PHP.

    Also accidentally found - http://php.iis.net/ it is 5.3.13 but it is one package which installs all needed. I did not try it yet but I will.

    You guys need to promote it on this page http://www.microsoft.com/en-us/download/details.aspx?id=20098 and may be create another installer for 5.4 :)


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.

    Saturday, August 11, 2012 4:21 AM
  • I am trying to point PHP to C:\PHP\php.ini

    Manual (http://www.php.net/manual/en/install.windows.iis7.php) says -

    appcmd.exe set config  -section:system.webServer/fastCgi ^
    /+"[fullPath='C:\php\php.exe',arguments=''].environmentVariables.^
    [name='PHPRC',value='C:\Some\Directory\']" /commit:apphost

    However it fails. First comment on the same page says:

    Example #9 fails unless I change "php.exe" to "php-cgi.exe" as follows:

    appcmd.exe set config  -section:system.webServer/fastCgi ^
    /+"[fullPath='C:\php\php-cgi.exe',arguments=''].environmentVariables.^
    [name='PHPRC',value='C:\PHP\']" /commit:apphost

    This command also fails.

    C:\Users\ivk>%windir%\system32\inetsrv\appcmd.exe set config  -section:system.we
    bServer/fastCgi ^
    More? /+"[fullPath='C:\PHP\php-cgi.exe',arguments=''].environmentVariables.^
    ERROR ( message:Unknown attribute "[fullPath='C:\PHP\php-cgi.exe',arguments=''].
    environmentVariables.^".  Replace with -? for help. )

    C:\Users\ivk>[name='PHPRC',value='C:\PHP\']" /commit:apphost

    What is a correct one?

    Thank you


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.

    Saturday, August 11, 2012 8:14 AM
  • I found how to do this in GUI. But I still have

    Configuration File (php.ini) Path C:\Windows
    Loaded Configuration File (none)


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.

    Saturday, August 11, 2012 9:00 AM
  • I solved all my problems. Installed http://php.iis.net/ than added 5.4.5 into C:\PHP and used PHP Manager inside IIS to add another PHP installation.

    You will have to configure extensions and all settings from IIS PHP consolde for both installations. In my case when I changed PHP to 5.4.5 it displayed loaded file C:\PHP\php.ini but all settings were not from it. It took me a while to realise I can change settings (extensions and all php ini params) directly in PHP IIS console and they persist. So you can change PHP version very easily as well as have a few php.ini files even for the same PHP version and change them in PHP IIS console.

    I recommend everyone to use http://php.iis.net/ installer and even if you do not want to use 5.3.13 you can always unpack other version  to C:\PHP4.5.4 and add it in PHP IIS console configure and use. PHP IIS installer will also install all required packages to use MS SQL server. See below.

    Just surprised nobody cares to contact PHP documentation site and ask to update it to at least mention this installer on IIS install page and MS SQL server support.


    -- Partner at Deep Shift Labs. We are building Nerrvana - Selenium cloud at your fingertips and Startyco - pluggable web apps for start-ups.


    Saturday, August 11, 2012 12:01 PM