none
Call to undefined function sqlsrv_connect()

    Pregunta

  • Hello,

    I've seen threads asking about this but I believe my situation is different.  I am trying to setup WordPress to run on SQL Server .  I think my problem is related to the sql server driver for PHP.  I am running the following setup:

     

    • Windows 7 x64
    • SQL Server 2008 R2
    • IIS 7.5
    • PHP 5.3.5
    • Microsoft SQL Driver for PHP v5.3 in IIS Express (installed from the web platform installer 3)

     

    I think the PHP installation overall is fine as I can load the initial Wordpress php page where it asks you for your database credentials.  When I submit them I get the following:

     

    Strict Standards: Redefining already defined constructor for class wpdb in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 388
    Strict Standards: Redefining already defined constructor for class SQL_Translations in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\translations\translations.php on line 153
    Strict Standards: Redefining already defined constructor for class Fields_map in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\translations\fields_map.php on line 37
    Fatal error: Call to undefined function sqlsrv_connect() in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 430
    Notice: Undefined property: wpdb::$dbh in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 476

     

    So I did do a little research on this already but still can't figure this out.  For some reason I did not have any variant of php_mssql.dll or php_sqlsrv_53_xx.dll in my extensions directory. I then manually downloaded the DLLs from here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05&displaylang=en

    I placed 'php_sqlsrv_53_ts_vc9.dll' and 'php_pdo_sqlsrv_53_ts_vc9.dll' into my extensions directory, added/enabled the extensions using PHP Manager and restarted the website in IIS and still get the same error.  I noticed they don't show up (at least I don't see them) when I do phpinfo().

    Any suggestions?

    jueves, 10 de febrero de 2011 2:59

Respuestas

  • The use of the version should depend on the way that IIS7 is configured to run PHP.  For example, if your IIS 7 is configured for FastCGI, you should use the Not Thread Safe version of the driver and use the Thread Safe version for a more standard CGI setup.

    For the driver from Microsoft ((php_sqlsrv_53_nts_vc9.dll), both versions should be able to work under the FastCGI mode but of course, with the Thread Safe version, you'll lose a lot of the speed avantage of using FastCGI in the first place.

    For the other driver, php_pdo_sqlsrv_53_nts_vc9.dll, I won't be surprised if the other Thread Safe version doesn't work under the FastCGI mode.

    Also, each time that you change the driver in the PHP.INI file, you should reboot your machine or, at least, reboot IIS7.


    Sylvain Lafontaine, ing.
    MVP - Access
    Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
    Independent consultant and remote programming for Access and SQL-Server (French)

    • Marcado como respuesta Ai-hua Qiu jueves, 17 de febrero de 2011 7:54
    sábado, 12 de febrero de 2011 6:39

Todas las respuestas

  • I was looking at the log file and saw some additional startup warnings:

     

     

    [10-Feb-2011 00:36:55] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\v5.3\ext\php_sqlsrv_53_ts_vc9.dll' - The specified module could not be found.

     in Unknown on line 0

    [10-Feb-2011 00:36:56] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\v5.3\ext\php_mssql.dll' - The specified module could not be found.

     in Unknown on line 0

    [10-Feb-2011 00:37:05] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\v5.3\ext\php_pdo_sqlsrv_53_ts_vc9.dll' - The specified module could not be found.

     in Unknown on line 0

    [10-Feb-2011 00:37:09] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\v5.3\ext\php_sqlsrv_53_ts_vc9.dll' - The specified module could not be found.

     in Unknown on line 0

    [10-Feb-2011 00:37:10] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\Program Files (x86)\PHP\v5.3\ext\php_mssql.dll' - The specified module could not be found.

     in Unknown on line 0

    [10-Feb-2011 00:58:52] PHP Fatal error:  Call to undefined function sqlsrv_connect() in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 430

    [10-Feb-2011 00:58:52] PHP Notice:  Undefined property: wpdb::$dbh in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 476

     

     

    I'm thinking to myself, I know those DLLs are indeed in the filesystem at the specified path.  I then got to wondering about permissions.  I checked the DLLs to see if I needed to 'Unblock' them...nope.  Then I checked the directory permissions.  I think I added NETWORK_SERVICE, LOCAL_SERVICE, IUSER, and a few other accounts and then it finally worked!

    --------------------------------

    Now I'm getting a new error:

    [10-Feb-2011 01:20:17] PHP Fatal error:  Call to undefined function wp_die() in F:\MontavestaNet\WordPress\Production\wp-includes\wp-db\sqlsrv\sqlsrv.php on line 1263

    From what I've read here: http://wordpress.jdwebdev.com/blog/undefined-wp-die-wordpress-mu-installation-error/ 

    It just means I have some bad user permissions on the DB or invalid credentials when I try to connect to SQL Server.  I made the account a server 'sysadmin' and I double checked the user/pass credentials and they are correct.  I can even go into the database and create/update/select from a table using the account.  So I'm not sure if this is something else.

    jueves, 10 de febrero de 2011 6:42
  • Strange, for database host I had tried 'server001\db001' and it didn't work. I remembered that I actually had tcp/ip set up for the server for direct internet access over a specified port with my DNS. So I tried 'mysite.net,12345' and it installed. Very strange I couldn't give it the local server/instance combo while on the box locally..
    jueves, 10 de febrero de 2011 6:59
  • Verify that the SQL-Server Browsing Service is up and running; it is needed to resolve an instance name to its port.


    Sylvain Lafontaine, ing.
    MVP - Access
    Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
    Independent consultant and remote programming for Access and SQL-Server (French)

    viernes, 11 de febrero de 2011 2:48
  • One last followup...the thread safe versions of the libraries do not seem to be working.  Only when I use the non thread safe version of the DLL extensions will PHP in IIS 7 recognize the MS SQL drivers.

    So only use:

    php_sqlsrv_53_nts_vc9.dll

    php_pdo_sqlsrv_53_nts_vc9.dll

    If you are going to use WordPress.

     

    sábado, 12 de febrero de 2011 2:11
  • The use of the version should depend on the way that IIS7 is configured to run PHP.  For example, if your IIS 7 is configured for FastCGI, you should use the Not Thread Safe version of the driver and use the Thread Safe version for a more standard CGI setup.

    For the driver from Microsoft ((php_sqlsrv_53_nts_vc9.dll), both versions should be able to work under the FastCGI mode but of course, with the Thread Safe version, you'll lose a lot of the speed avantage of using FastCGI in the first place.

    For the other driver, php_pdo_sqlsrv_53_nts_vc9.dll, I won't be surprised if the other Thread Safe version doesn't work under the FastCGI mode.

    Also, each time that you change the driver in the PHP.INI file, you should reboot your machine or, at least, reboot IIS7.


    Sylvain Lafontaine, ing.
    MVP - Access
    Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
    Independent consultant and remote programming for Access and SQL-Server (French)

    • Marcado como respuesta Ai-hua Qiu jueves, 17 de febrero de 2011 7:54
    sábado, 12 de febrero de 2011 6:39