I’ve been killing my brain over this for a few hours while I was running into another issue, I feel the answer is so simple but I’ve been unable to solve it.
I’m attempting to connect into a SQL Server DB I have hosted on my Linux VM. I’m running xampp on my development windows machine and the connection is coming from a php site I’m building. I figured I’d need to use sqlsrv to connect in. I downloaded the dll’s from https://docs.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15&viewFallbackFrom=sql-server-2019
I’ve moved the necessary dll files to my xamppphpetc directory. I’ve also verified the extension directory in the php.ini file is extension_dir="C:xamppphpext"
The following have been added to the Dynamic Extensions section of the php.ini:
extension=php_sqlsrv_81_ts_x86.dll
extension=php_pdo_sqlsrv_81_ts_x86.dll
extension=php8ts.dll
I’ve found info online about removing the php_ prefix, removing the .dll suffix, using ts or non ts, moving all files into the extensions directory, moving only the couple listed above into the directory, not including php8ts.dll, etc. I’ve tried every configuration of the above, both logical and illogical.
Here’s a sample connection code for my site:
$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’ve tried multiple different connection examples. With the one above, I receive this error:
Fatal error: Uncaught PDOException: could not find driver in C:xampphtdocssiteindex.php:123 Stack trace: #0 C:xampphtdocssiteindex.php(123): PDO->__construct('sqlsrv:Server=my_server_ip', 'username', 'password') #1 {main} thrown in C:xampphtdocssiteindex.php on line 123
From here I logically thought okay, let’s check phpinfo(); by echoing it. There is nothing at all listed for sqlsrv or the PDO variant anywhere on the list. Even ctrl+f on the page for sqlsrv, the only thing that is found is the error above.
I have verified I have the ODBC drivers installed.
The other things I’ve tried was to use sqlsrv_connect instead of PDO. I found conflicting information on this working for my php version (8.1), but figured what the hell, let’s try it anyways. However when I run into that variant, I get:
Fatal error: Call to undefined function sqlsrv_connect()
It seems obvious to me my .dlls are not being recognized or something of the sort. However I cannot for the life of me understand why. I’ve verified everything is ran as admin, restarted xampp multiple times, removed/redownloaded the dlls, etc.
Can anyone point out any glaring problems I may not be thinking of?
