Issues connecting to Microsoft SQL from PHP

折月煮酒 提交于 2019-12-11 23:26:56

问题


I am building a website using PHP on Somee Server(somee.com) and Microsoft SQL. Now I have a problem making connection between php and SQL.

Here is my connection code:

<?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));} ?>

And it returns me this error:

Connection could not be established. Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jason_SQLLogin'. ) )

Anyone knows about it? Thanks very much. Really appreciate it.


回答1:


If you say you have the correct username / pass, perhaps the server (some.com) is actively blocking connections to it.

Try using below steps -

  1. On SQL Server (of SOMEE) in Security, make sure that Server Authentication is set to SQL Server and Windows Authentication Mode. This allows SQL server to authenticate username and passwords.

  2. Configure Server firewall to allow connections to SQL server.



来源:https://stackoverflow.com/questions/20276873/issues-connecting-to-microsoft-sql-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!