簡體   English   中英

我如何從PHP連接到MSSQL數據庫

[英]How do i connect to MSSQL database from php

我有一個Windows Azure服務器,我想從PHP應用程序連接到MSSQL服務器。 但是,當我嘗試連接到數據庫時,會彈出一條錯誤消息,說...

Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) ) 

我用這段代碼連接數據庫..

<?php
    $serverName = "AZR-SRV-MAP01"; //serverName\instanceName

    // Since UID and PWD are not specified in the $connectionInfo array,
    // The connection will be attempted using Windows Authentication.
    $connectionInfo = array( "Database"=>"EmpSys");
    $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));
    }
?>

我正在使用Windows身份驗證訪問數據庫,因此我沒有指定UIDPWD參數。

請幫我連接到SQL服務器。

您可以查看此已發布的有關此主題的答案。 它似乎可以幫助你。

使用PHP的MSSQL連接

祝好運 :)

從PHP連接到MSSQL數據庫的工作代碼(感謝gofr1)..

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

    // Since UID and PWD are not specified in the $connectionInfo array,
    // The connection will be attempted using Windows Authentication.
    $connectionInfo = array( "Database"=>"db_name");
    $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));
    }
?>

編輯

您需要打開Windows身份驗證,並在IIS設置中設置匿名身份驗證。 通過本地/域帳戶授權SQL Server。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM