0
votes

The setup:

  • Windows 10 Pro x64
  • PHP version: 7.2.10
  • ODBC v17 Installed

php_sqlsrv_7_nts_x64.dll and php_sqlsrv_7_ts_x64.dll (all dll's are in C:\xampp\php\ext)

Loaded Configuration File C:\xampp\php\php.ini

php.ini:

line 1965 of php.ini:
extension=php_sqlsrv_7_nts_x64.dll

lines 910-913: (previoius attempt)
[PHP_SQLSRV]
;extension=php_sqlsrv.dll
extension_dir = "C:\xampp\php\ext"  
extension=php_sqlsrv_7_ts_x64.dll

cmd iisreset and Apache Server restarted between each attempt

But I am getting

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()

I've also completely closed xampp and restarted it a number of times.

PHP Info

To be clear, there is NO php.ini file in C:\Windows Opening php.ini via Xampp's config button opens C:\xampp\php\php.ini and that is the file I've been modifying.

This now appears in PHP Info: SQLSRV extension showing

[08-Apr-2021 22:20:04 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0

[08-Apr-2021 22:20:04 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:04 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_pdo_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pdo_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:05 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:05 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:05 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_pdo_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pdo_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 15:20:07 America/Los_Angeles] PHP Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\chart\ms_sql_test.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\chart\ms_sql_test.php on line 19 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_pdo_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pdo_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 22:20:22 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_ts_x86' (tried: C:\xampp\php\ext\php_pdo_sqlsrv_7_ts_x86 (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pdo_sqlsrv_7_ts_x86.dll (The specified module could not be found.)) in Unknown on line 0 [08-Apr-2021 15:20:23 America/Los_Angeles] PHP Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\chart\ms_sql_test.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\chart\ms_sql_test.php on line 19 [08-Apr-2021 15:20:25 America/Los_Angeles] PHP Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\chart\ms_sql_test.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\chart\ms_sql_test.php on line 19

1
My guess, you've editted the wrong php.ini file. Is C:\xampp\php\php.ini really the php.ini file that apache is using? - Larnu
One dll is thread safe (ts) and the other is not (nts,) that is probably your problem. Check if your php is ts or nts and download the correct dll ;) - Orry
Thank you I'll double check both of these right now! - Mikey
re: Orry, I've tried all 4 dll's, none work. PHP Info says thread safety is enabled so I will keep php_sqlsrv_7_ts_x86.dll as PHP info is actually reporting architecture x86 - Mikey
@Larnu, wouldn't it be the one PHP Info's Loaded Configuration File points to? - Mikey

1 Answers

0
votes

This issue was fixed by correcting the versions of Microsoft's dll's designed to work with the version of PHP I had.

My PHP is v7.2 php_sqlsrv_7_XX_XX.dll does not work with PHP 7.2

I instead had to download php_sqlsrv.dll from https://pecl.php.net/package/sqlsrv/5.9.0preview1/windows to match my PHP v7.2

Doing this and then updating the config instantly fixed the issue (after an Apache reboot)!

Please see https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15#driver-versions to get the correct version of MS' dll to match the version of PHP you're running.