2017-08-04 76 views
0

請嘗試連接到不同機器上的mssql數據庫。下面是我的代碼,但我只是不斷得到一個空白頁。使用PHP連接MSSQL數據庫連接

我不知道這個問題可能是什麼。我已經安裝了php和mssql驅動程序。

<?php 

    $uid = "******"; 
    $pwd = "***\$\$****"; 
    $DB = "***********"; 
    $serverName = "192.***.**.***"; 
    $connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=> $DB, "ReturnDatesAsStrings" => true); 
    $conn = sqlsrv_connect($serverName, $connectionInfo); 

if($conn) { 
    echo "Connection established.<br />"; 
}else{ 

    echo "Connection could not be established.<br />"; 
    die(print_r(sqlsrv_errors(), true)); 
} 

?> 
+0

檢查與此同時使連接:' 「數據庫」=> 「數據庫名」, 「UID」=> 「userName」,「PWD」=>「密碼」' – ggupta

回答

0

我建議您使用sqlsrv_errors()來顯示連接錯誤。

加載php.ini文件中的PHP驅動程序並重新啓動服務器。

extension=php_pdo_sqlsrv_54_ts.dll 
extension=php_sqlsrv_54_ts.dll 

請看下面的例子:

<?php 
    $serverName = "serverName\sqlexpress"; //serverName\instanceName 

    // Since UID and PWD are not specified in the $connectionInfo array, 
    // The connection will be attempted using Windows Authentication. 
    $connectionInfo = array("Database"=>"dbName"); 
    $conn = sqlsrv_connect($serverName, $connectionInfo); 

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

欲瞭解更多信息:http://php.net/manual/en/function.sqlsrv-connect.php