使用PDO连接到SQL Server 2008 [英] Connect to SQL Server 2008 with PDO

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

问题描述

我正在尝试使用Windows XP sp2上的PHP 5.2.9-2连接到SQL Server 2008(未表达).我可以从同一台计算机上的SQL Server Management Studio中连接到远程SQL Server.

I am trying to connect to SQL Server 2008 (not express) with PHP 5.2.9-2 on Windows XP sp2. I can connect to the remote SQL Server fine from SQL Server Management Studio from the same machine.

我的第一次尝试是

$conn = new PDO("mssql:host={$host};dbname={$db}", $user, $pass);

哪个出现此错误:


PHP Fatal error:  
Uncaught exception 'PDOException' with message 
'SQLSTATE[0100] Unable to connect: SQL Server is unavailable or does not exist.  
Access denied. (severity 9)'

第二次尝试(位于专家交换)

$conn = new PDO("odbc:Driver={SQL Server Native Client 10.0};Server={$host};Database={$db};Uid={$user};Pwd={$pass}", 
                         $user, $pass);

这可行,但是我不能使用PDO::lastInsertId(),我希望能够:

This works, but I can't use PDO::lastInsertId(), which I would like to be able to:

 Driver does not support this function: driver does not support lastInsertId()

您有什么建议吗?任何帮助将不胜感激.

Do you have any suggestions? Any help would be greatly appreciated.

推荐答案

我非常确定具有mssql数据服务器类型的pdo需要dblib进行连接.您是否在计算机上安装了dblib?确保您可以在系统路径中的某处找到ntwdblib.dll.我知道这与您收到的错误消息并不吻合,但是我不确定我是否信任该错误消息.

i'm pretty sure that pdo with the mssql data server type requires dblib to connect. do you have dblib installed on the machine? make sure you can find ntwdblib.dll somewhere in the path on your system. i know this doesn't jive with the error message you're getting, but i'm not sure i trust the error message.

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

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