使用 SQL Server 驱动程序通过 PDO 连接到 SQL Server [英] Connect to SQL Server through PDO using SQL Server Driver

查看:45
本文介绍了使用 SQL Server 驱动程序通过 PDO 连接到 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有 Microsoft 提供的驱动程序.

I am trying to connect to an existing SQL Server database using PDO with the drivers provided by Microsoft.

我见过使用 odbc、dblib、mssql 等的示例,但是我认为这些驱动程序的连接字符串应该使用 'sqlsrv'?

I have seen examples using odbc, dblib, mssql, etc., however I believe the connection string with these drivers should use 'sqlsrv'?

是否有任何关于如何正确执行此操作的好示例?如果我应该通过其他方法执行此操作,请告诉我.谢谢!

Are there any good examples of how to properly do this? If I should be doing this via some other method please let me know. Thanks!

推荐答案

好吧,PDO 的最大优点是可以非常轻松地访问任何数据库.如果您已经安装了这些驱动程序,您应该可以:

Well that's the best part about PDOs is that it's pretty easy to access any database. Provided you have installed those drivers, you should be able to just do:

$db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password");

这篇关于使用 SQL Server 驱动程序通过 PDO 连接到 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆