问题
I have tried scouring the internet about this, but cannot seem to find a resolution, so I apologise in advance if this is a duplicate as I cannot seem to find anything that helps my situation.
I have setup a new WAMP 3.1.3 Server installation and I'm trying to run a Laravel 5.6 application. The application connects to a remote MSSQL database on the network and I have this running successfully on my Homestead test environment using the same PHP version (but Ubuntu).
On my WAMP Server (Microsoft Server 2016), I have installed the PHP 7.1 SQL drivers from https://github.com/Microsoft/msphpsql/releases/tag/v5.3.0. I have edited my php.ini
files to enable the drivers like so:
[PHP_SQLSRV]
extension=php_sqlsrv_71_ts.dll
[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_71_ts.dll
I can visually see in the WAMP tray utility that php_pdo_sqlsrv_71_ts
and php_sqlsrv_71_ts
is ticked on and enabled for the PHP extensions. I have ran php -m
and can see that the following modules are installed and enabled:
...
PDO
pdo_mysql
pdo_sqlite
pdo_sqlsrv
...
I have ran phpinfo() and can see that pdo_sqlsrv
is also installed:
However, when I attempt a connection to the remote database, I get the following error:
Illuminate\Database\QueryException: SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user ...
I am using window authentication as the database login, and I have installed SQL Management Studio on my WAMP Server and connected successfully to the database with my windows credentials, so I can verify that it is not a username or password issue.
I can confirm that all details in my .env
file are correct and are a complete duplicate of my Homestead test environment.
I proceeded to attempt to install the ODBC Driver 13 for SQL Server, however, upon installation I get the following error:
Installation of ODBC Driver 13 for SQL Server failed because a higher version already exists on the machine.
When I check my installed programs it shows that version 11 and 13 are already installed:
I have also tried enabling the php_odbc
and php_pdo_odbc
modules but that didn't make any difference either.
My WAMP setup looks like so:
I really don't know what else to try. Maybe I have missed something?
回答1:
Turns out it didn't like me trying to access the database via Windows Authentication. Thanks to this post Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'sa' I was able to determine that SQL was throwing an error about not liking my username/password.
Strangely enough, even though I could access the remote database using my Windows credentials through Management Studio on the same machine, the PHP driver must have been a different story.
I created a new user account against the database and was able to login no problem.
来源:https://stackoverflow.com/questions/51529993/unable-to-connect-to-remote-sql-database-from-wamp-server-using-php-7-1