从PHP连接到Microsoft SQL的问题

时间:2013-11-29 00:59:14

标签: php sql-server sqlsrv

我正在使用Somee Server(somee.com)上的PHP和 Microsoft SQL 构建一个网站。现在我在php和SQL之间建立连接时遇到了问题。

这是我的连接代码:

<?php
$serverName = "mssql.somee.com"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"myDB","UID"=>"myusername","PWD"=>"mypassword");
$conn = sqlsrv_connect( "mssql.somee.com", $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));} ?>

它返回给我这个错误:

  

无法建立连接。数组([0] =&gt;数组([0] =&gt;   28000 [SQLSTATE] =&gt; 28000 [1] =&gt; 18456 [code] =&gt; 18456 [2] =&gt;   [Microsoft] [SQL Server Native Client 11.0] [SQL Server]登录失败   用户'jason_SQLLogin'。 [message] =&gt; [Microsoft] [SQL Server Native   客户端11.0] [SQL Server]用户'jason_SQLLogin'登录失败。 )[1]   =&GT;数组([0] =&gt; 28000 [SQLSTATE] =&gt; 28000 [1] =&gt; 18456 [code] =&gt; 18456 [2] =&gt; [Microsoft] [SQL Server Native Client 11.0] [SQL   服务器]用户'jason_SQLLogin'登录失败。 [message] =&gt;   [Microsoft] [SQL Server Native Client 11.0] [SQL Server]登录失败   用户'jason_SQLLogin'。 ))

有人知道吗?非常感谢。真的很感激。

1 个答案:

答案 0 :(得分:1)

如果您说您拥有正确的用户名/密码,那么服务器(some.com)可能会主动阻止与它的连接。

尝试使用以下步骤 -

  1. 在安全性的SQL Server(SOMEE​​)上,确保该服务器 身份验证设置为SQL Server和Windows身份验证模式。 这允许SQL服务器验证用户名和密码。

  2. 配置服务器防火墙以允许连接到SQL服务器。

相关问题