无法使用PHP 7.1从WAMP Server连接到远程SQL数据库 [英] Unable to connect to remote SQL database from WAMP Server using PHP 7.1

查看:148
本文介绍了无法使用PHP 7.1从WAMP Server连接到远程SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在互联网上搜寻此消息,但似乎找不到解决方法,因此如果这是重复的操作,我会道歉,因为我似乎找不到任何可以帮助我解决问题的方法.

我已经安装了新的WAMP 3.1.3 Server,并且正在尝试运行Laravel 5.6应用程序.该应用程序连接到网络上的远程MSSQL数据库,并且我已使用相同的PHP版本(但Ubuntu)在Homestead测试环境中成功运行了该数据库.

在WAMP服务器(Microsoft Server 2016)上,我已经从 https://github.com/Microsoft/msphpsql/releases/tag/v5.3.0 .我已经编辑了php.ini文件以启用如下驱动程序:

[PHP_SQLSRV]
extension=php_sqlsrv_71_ts.dll
[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_71_ts.dll

我可以在WAMP托盘实用程序中直观地看到php_pdo_sqlsrv_71_tsphp_sqlsrv_71_ts已被选中并启用了PHP扩展.我已经运行php -m,可以看到已安装并启用了以下模块:

...
PDO
pdo_mysql
pdo_sqlite
pdo_sqlsrv
...

我已经运行了phpinfo(),可以看到还安装了pdo_sqlsrv:

但是,当我尝试连接到远程数据库时,出现以下错误: Illuminate\Database\QueryException: SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user ...

我正在使用窗口身份验证作为数据库登录名,并且已在WAMP Server上安装了SQL Management Studio,并已使用Windows凭据成功连接到数据库,因此可以验证这不是用户名或密码问题. /p>

我可以确认.env文件中的所有详细信息都是正确的,并且与Homestead测试环境完全相同.

我继续尝试为SQL Server安装ODBC驱动程序13,但是,在安装时出现以下错误: Installation of ODBC Driver 13 for SQL Server failed because a higher version already exists on the machine.

当我检查已安装的程序时,它表明已经安装了版本11和13:

我也尝试过启用php_odbcphp_pdo_odbc模块,但这也没有任何区别.

我的WAMP设置如下:

我真的不知道还能尝试什么.也许我错过了什么?

解决方案

原来,我不喜欢尝试通过Windows身份验证访问数据库.感谢这篇文章 Microsoft ODBC Driver 13对于SQL Server:用户'sa'登录失败我能够确定SQL抛出了一个关于不喜欢我的用户名/密码的错误.

奇怪的是,即使我可以使用Windows凭据通过同一台计算机上的Management Studio访问远程数据库,但PHP驱动程序肯定是另外一回事.

我针对该数据库创建了一个新的用户帐户,并且无法登录.

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?

解决方案

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.

这篇关于无法使用PHP 7.1从WAMP Server连接到远程SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆