PHP PDO Connection to SQL Server with integrated security?(PHP PDO 连接到具有集成安全性的 SQL Server?)
问题描述
我可以使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP PDO 连接到具有集成安全性的 SQL Server?


基础教程推荐
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- Web 服务器如何处理请求? 2021-01-01