問題描述
我可以使用 PDO 和使用 mssql 驅(qū)動(dòng)程序的集成安全性連接到 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 身份驗(yàn)證可以很好地工作,但是必須為大量數(shù)據(jù)庫(kù)創(chuàng)建 SQL Server 登錄名很痛苦,因此如果可能,最好使用集成安全性.我在 Windows 上將 PHP 作為 CLI 運(yùn)行.
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.
推薦答案
該站點(diǎn)幫助:用于 PHP 的 SQL Server 驅(qū)動(dòng)程序:了解 Windows 身份驗(yàn)證
解決我的問題的要點(diǎn)是:
The gist of it that fixed my issue was:
- 啟用 Windows 身份驗(yàn)證
- 禁用匿名身份驗(yàn)證
- 從 PDO 連接中刪除用戶名和密碼
$conn = new PDO( "sqlsrv:server=$serverName ; Database=$dbName" );
我的測(cè)試是使用 2010 年 6 月發(fā)布的最新驅(qū)動(dòng)程序(用于 PHP 2.0 CTP2 的 SQL Server 驅(qū)動(dòng)程序).
My testing was with the newest driver released June 2010 (SQL Server Driver for PHP 2.0 CTP2).
這篇關(guān)于PHP PDO 連接到具有集成安全性的 SQL Server?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!