問題描述
我可以使用 PDO 和使用 mssql 驅動程序的集成安全性連接到 SQL Server 2008 嗎?目前正在做這樣的事情來正常連接:
Can I connect to SQL Server 2008 using PDO and integrated security using the mssql driver? Currently doing something like this to connect normally:
$db = new PDO("mssql:host=host;dbname=db", "user", "pass");
使用 SQL Server 身份驗證可以很好地工作,但是必須為大量數據庫創建 SQL Server 登錄名很痛苦,因此如果可能,最好使用集成安全性.我在 Windows 上將 PHP 作為 CLI 運行.
This works fine using SQL Server authentication, but it is a pain having to create SQL server logins for loads of databases, so it would be nice to use integrated security if possible. I am running PHP as CLI on Windows.
推薦答案
該站點幫助:用于 PHP 的 SQL Server 驅動程序:了解 Windows 身份驗證
解決我的問題的要點是:
The gist of it that fixed my issue was:
- 啟用 Windows 身份驗證
- 禁用匿名身份驗證
- 從 PDO 連接中刪除用戶名和密碼
$conn = new PDO( "sqlsrv:server=$serverName ; Database=$dbName" );
我的測試是使用 2010 年 6 月發布的最新驅動程序(用于 PHP 2.0 CTP2 的 SQL Server 驅動程序).
My testing was with the newest driver released June 2010 (SQL Server Driver for PHP 2.0 CTP2).
這篇關于PHP PDO 連接到具有集成安全性的 SQL Server?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!