使用PDO的odbc通过Windows身份验证连接到MSSQL服务器实例 [英] Using PDO's odbc to connect to a MSSQL server instance with Windows Authentication
问题描述
我正在尝试使用带有odbc的PDO连接到MSSQL数据库.我知道有一个软件包SqlSrv
(但是由于某些原因,该软件包(.dll
)无法正确加载).因此,我发现一些文档争论说PDO也有可能.在我的PHP.ini
中,我启用了扩展名php_pdo_odbc.dll
,它可以很好地加载.
I'm trying to connect to a MSSQL database using PDO with odbc. I'm aware that there's a package SqlSrv
(but for some reason that package (.dll
) won't load properly). So I found some documentation arguing it's also possible with PDO. In my PHP.ini
I've enabled the extension php_pdo_odbc.dll
and it loads fine.
我的连接字符串如下:
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;',
'MyWindowsUserName',
'MyWindowsPassword'
);
我尝试了各种属性(例如,将域添加到用户名之前,使用身份验证选项用户ID","UID",密码","PWD"和受信任的连接"进行切换),但是我一直收到消息
I've tried various properties (for example by prepending the domain to the username, switching with the authentication options User Id, UID, Password, PWD and Trusted Connection) but I keep getting the message
SQLSTATE [28000] SQLDriverConnect:18456 [Microsoft] [ODBC SQL Server 驱动程序] [SQL Server]用户"MyWindowsUserName"的登录失败.
SQLSTATE[28000] SQLDriverConnect: 18456 [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'MyWindowsUserName'.
关于如何使用Windows帐户连接到数据库的任何建议? (这是我连接到数据库的唯一方法)
Any suggestions on how to connect to the database with my Windows Account? (that's the only way for me to connect to the database)
推荐答案
尝试删除用户名&密码
Try removing the username & password
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;'
);
这篇关于使用PDO的odbc通过Windows身份验证连接到MSSQL服务器实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!