XAMPP/SQLSRV: Unable to find Sqlsrv in PHPINFO(); - error from connection
P粉201448898
P粉201448898 2023-11-09 22:34:33
0
1
699

I'm trying to connect to my SQL Server database hosted on a Linux VM. I'm running xampp on my development windows machine, and the connection is from a php site I'm building. I think I need to use sqlsrv to connect. I downloaded the dll sql-server-ver15&viewFallbackFrom=sql-server-2019## from https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view= #

I have moved the necessary dll files to my

xamppphpetc directory. I also verified that the extension directory in the php.ini file is extension_dir="C:xamppphpext"

The following has been added to the

Dynamic Extensions section of php.ini:

extension=php_sqlsrv_81_ts_x86.dll
extension=php_pdo_sqlsrv_81_ts_x86.dll
extension=php8ts.dll

I found information online about removing the

php_ prefix, removing the .dll suffix, using ts or not ts, moving all files to the extension directory, only the ones listed above Several files were moved to the directory information, excluding php8ts. dll etc. I have tried every configuration above, both logical and illogical.

This is the sample connection code for my website:

$conn = new PDO('sqlsrv:Server=my_server_ip\MSSQLSERVER;Database=dbname', 'username', 'password');
if ($conn === false) {
    echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
    exit;
} else {
    echo "success";
}

I tried multiple different connection examples. By doing the above, I get this error:

Fatal Error: Uncaught PDOException: Driver not found in C:xampphtdocssiteindex.php:123 Stack trace: #0 C:xampphtdocssiteindex.php(123): PDO ->__construct('sqlsrv:Server= my_server_ip', 'username', 'password') #1 {main} throws in C:xampphtdocssiteindex.php on line 123

From here I logically thought okay, let's check by echoing

phpinfo(); . There is nothing listed for sqlsrv or PDO variants anywhere in the list. Even if you ctrl f on the sqlsrv page, you can only find the above error.

I have verified that the ODBC driver is installed.

Other things I've tried is using

sqlsrv_connect instead of PDO. I found conflicting information regarding my php version (8.1) but thought I'd give it a try anyway. However, when I encounter that variant I get:

Fatal error: Calling undefined function sqlsrv_connect()

To me it's obvious that my .dll isn't being recognized or something like that. Yet for the life of me I can't understand why. I've verified everything is running as administrator, restarted xampp multiple times, deleted/redownloaded the dlls, etc.

Can anyone point out any obvious issues that I might not have thought of?

P粉201448898
P粉201448898

reply all(1)
P粉798010441

solved. There are two questions.

  1. My Xampp installation is corrupted. It doesn't recognize any of the new DLLs I noticed when using echo phpinfo(); on the page.

  2. For some reason the ini file configuration tries to use x86 dlls instead of x64, even though the extension is written in the ini as x64.

Solution steps:

  1. I reinstalled and reconfigured Xampp again using default settings and now the dll is recognized.

  2. I removed the x86 dll from Xampp's extensions directory.

The final php.ini is like this:

extension=php_sqlsrv_81_ts_x64.dll
extension=php_pdo_sqlsrv_81_ts_x64.dll
extension=php8ts.dll
extension=php_pdo_odbc.dll
extension=php_pdo.dll

Using the final .dll may be redundant, but it will still work as expected. Make sure to verify the correct version of sqlsrv or pdo_sqlsrv as there may be compatibility issues with your version of php.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template