使用PHP PDO连接到MSSQL Server 2005

时间:2014-03-28 09:10:47

标签: php pdo timeout sqlsrv

我正在尝试与PHP和MS SQL Server 2005建立连接。我在Windows 8和PHP版本5.3.28中使用IIS 8。我已经完成了我的研究,我已经找到了MSSQL PHP PDO(http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.phphttp://technet.microsoft.com/en-us/library/ff754357(v=sql.105).aspx),下载并启用了我从微软网站找到的所有与PDO相关的DLL(Microsoft Drivers 3.0)对于PHP for SQL Server)并确保它们反映在phpinfo()中。

extension=php_pdo_sqlsrv_52_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts.dll
extension=php_pdo_sqlsrv_53_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
extension=php_sqlsrv_53_ts_vc9.dll

Stock Over Flow中的以下链接也让我陷入了困境:

我能够修复未找到的"驱动程序"和"连接字符串无效"问题,这是我目前的PHP代码:

$db_server = "func.website.com,8787";
//$db_server = "func.website.com:8787\sqlexpress";
$db_database = "db_BreadNButter";
$db_user = "tinapay";
$db_passwd = "p@ssword";

try {
   //$db = new PDO ("mssql:host=$db_server;dbname=$db_database;", $db_user, $db_passwd);
   $db = new PDO ("sqlsrv:Server=$db_server;Database=$db_database;", $db_user, $db_passwd);
} catch(PDOException $exception) {
   die("Unable to open database.<br>Error message:<br><br>$exception.");
}

我认为(手指交叉)我已经建立了与MSSQL DBase的连接,但是我收到了以下错误:

exception 'PDOException' with message 'SQLSTATE[08001]:
[Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258].
' in C:\inetpub\wwwroot\breadnbutter\class.connection.php:12 Stack trace: #0
C:\inetpub\wwwroot\breadnbutter\class.connection.php(12):
PDO->__construct('sqlsrv:Server=f...', 'tinapay', 'p@ssword') #1 {main}.

任何人都可以告诉我为什么会出现超时错误以及如何解决此问题?

3 个答案:

答案 0 :(得分:1)

端口应为func.website.com:8787。你的逗号有拼写错误。

答案 1 :(得分:1)

如何在php 5.4.4中连接sqlsrv 2008 错误是: 排列 (     [0] =&gt;排列         (             [0] =&gt; IMSSP             [SQLSTATE] =&gt; IMSSP             [1] =&gt; -49             [code] =&gt; -49             [2] =&gt;此扩展需要Microsoft SQL Server 2012 Native Client。访问以下URL以下载x86的Microsoft SQL Server 2012 Native Client ODBC驱动程序:http://go.microsoft.com/fwlink/?LinkId=163712             [message] =&gt;此扩展需要Microsoft SQL Server 2012 Native Client。访问以下URL以下载x86的Microsoft SQL Server 2012 Native Client ODBC驱动程序:http://go.microsoft.com/fwlink/?LinkId=163712         )

[1] => Array
    (
        [0] => IM002
        [SQLSTATE] => IM002
        [1] => 0
        [code] => 0
        [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
        [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    )

答案 2 :(得分:0)

我仍然遇到这个问题,但我能够说服我的老板使用asp而不是PHP。非常感谢那些帮助我的人。