简体   繁体   English

使用 PHP 中的 sqlsrv 时登录失败

[英]Login failed when using sqlsrv from PHP

I am trying to set up a WAMP server on Windows 2008 R2.我正在尝试在 Windows 2008 R2 上设置 WAMP 服务器。 Have Apache, PHP, and MySQL working.让 Apache、PHP 和 MySQL 正常工作。 Issue is concerning connecting to a MS SQL server.问题与连接到 MS SQL 服务器有关。 My login fails.我的登录失败。

SQLSTATE: 28000 Code: 18456 Message: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'Dataread'. SQLSTATE:28000 代码:18456 消息:[Microsoft][用于 SQL 服务器的 ODBC 驱动程序 11][SQL Server]用户“Dataread”登录失败。

I am currently running a LAMP server and can log in to the MS SQL server using the same credentials.我目前正在运行 LAMP 服务器,并且可以使用相同的凭据登录到 MS SQL 服务器。 I have verified the connection information (TCP, IP address, port).我已经验证了连接信息(TCP、IP 地址、端口)。 SQL server is not on this server. SQL 服务器不在此服务器上。 IIS is not running. IIS 未运行。 The login account is not a Windows account.登录帐户不是 Windows 帐户。

$serverName = "tcp:192.168.xxx.xxx,1433";  
$connectionOptions = array("Database"=>"[Hill Country MHDD Centers]",  "Uid"=>"Dataread", "PWD"=>"xxxxxxxx");  
        $conn = sqlsrv_connect($serverName, connectionOptions);  

What am I missing?我错过了什么?

After much digging and experimenting, discovered that the bracket around the database name was causing the problem.经过大量挖掘和试验,发现数据库名称周围的括号导致了问题。 Removed them and it works.删除它们并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM