2014-05-19 5 views
1

PHP를 mssql 데이터베이스에 연결하려고합니다. Windows 인증을 사용하거나 만든 사용자를 사용하여 mssql에 로그인 할 수 있습니다. 다음은 PHP 테스트 스크립트입니다PHP를 mssql 데이터베이스에 연결

<?php 

$serverName = "SUPERMAN"; 

$connectionInfo = array('Database'=>'xikwambene'); 
$conn = sqlsrv_connect($serverName, $connectionInfo); 

if($conn) { 
    echo "Connection establish.<br />"; 
}else { 
    echo "Connection could not be established.<br />"; 
    die(print_r(sqlsrv_errors(), true)); 
} 


?> 

그러나 나는 다음과 같은 오류 얻을 :

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 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'.) [1] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "xikwambene" requested by the login. The login failed. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "xikwambene" requested by the login. The login failed.) [2] => Array ([0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'.) [3] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "xikwambene" requested by the login. The login failed. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "xikwambene" requested by the login. The login failed.))

이 오류는 연결 세부 사항 실패 로그인에 의한 설립 할 수 없음을 보여줍니다. 내 코드에 로그인 세부 정보를 추가해야하는 경우 어떻게해야합니까? 도와주세요

+0

팁 : 오류 메시지를 일반적으로 HTML이 포함되어 있지 않습니다. 브라우저의 "소스보기"메뉴에서 공백을 읽으면 공백이 보이지 않습니다. –

+0

'NT AUTHORITY \ SYSTEM'은 Windows 서비스의 익명 계정입니다. 정말로 SQL Server에 액세스해야합니까? –

답변

2

설명서에서 :

Microsoft SQL Server 데이터베이스에 대한 연결을 엽니 다. 기본적으로 Windows 인증을 사용하여 연결이 시도됩니다. SQL Server 인증을 사용하여 연결하려면 연결 옵션 배열에 "UID"및 "PWD"를 포함시킵니다.

그래서 당신에서 ConnectionInfo이 추가 :

$connectionInfo = array('Database'=>'xikwambene', "UID"=>"userName", "PWD"=>"password"); 
관련 문제