首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从php连接到MSSQL数据库?

如何从php连接到MSSQL数据库?
EN

Stack Overflow用户
提问于 2016-09-30 00:40:07
回答 2查看 993关注 0票数 1

我有一台Windows Azure服务器,并且我希望从PHP应用程序连接到MSSQL服务器。但当我尝试连接到数据库时,它弹出一条错误消息...

代码语言:javascript
复制
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'. ) ) 

我使用此代码连接到数据库..

代码语言:javascript
复制
<?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 Authentication访问数据库,因此我没有指定UIDPWD参数。

请帮助我连接到SQL server。

EN

回答 2

Stack Overflow用户

发布于 2016-09-30 01:55:07

你可以查看这个已经发布的关于这个主题的答案。看起来这对你有帮助。

MSSQL connection using PHP

祝你好运:)

票数 0
EN

Stack Overflow用户

发布于 2016-09-30 02:32:24

从PHP连接到MSSQL数据库的工作代码(多亏了gofr1)。

代码语言:javascript
复制
<?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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39775743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档