【问题标题】:SQLSRV PDO DSN String EndedSQLSRV PDO DSN 字符串结束
【发布时间】:2015-10-29 13:28:13
【问题描述】:

我一直在努力让 mssql PDO 扩展在 PHP 4 中工作,然后才意识到它不能。所以我设法在 Windows Server 2012 上加载了 sqlsrv 扩展,它似乎正在找到驱动程序并将其加载到 PHP 中更正,但似乎我的 DSN 不正确,我不知道为什么.. . 这是我的连接代码...

    $ebilling = new PDO('sqlsrv:'.$myHost, $myUser, $myPass);
    $ebilling->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

这是我在页面上遇到的错误...

object(PDOException)#2 (8) { ["message":protected]=> string(51)     "SQLSTATE[IMSSP]: The DSN string ended unexpectedly." ["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "IMSSP" ["file":protected]=> string(54) "E:\Websites\myAccountErrorLog\config\mssql_connect.php" ["line":protected]=> int(16) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(54) "E:\Websites\myAccountErrorLog\config\mssql_connect.php" ["line"]=> int(16) ["function"]=> string(11) "__construct" ["class"]=> string(3) "PDO" ["type"]=> string(2) "->" ["args"]=> array(3) { [0]=> string(13) "sqlsrv:portal" [1]=> string(5) "ITDev" [2]=> string(7) "ITDevPW" } } [1]=> array(4) { ["file"]=> string(51) "E:\Websites\myAccountErrorLog\myaccounterrorlog.php" ["line"]=> int(8) ["args"]=> array(1) { [0]=> string(54) "E:\Websites\myAccountErrorLog\config\mssql_connect.php" } ["function"]=> string(7) "require" } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "IMSSP" [1]=> int(-65) [2]=> string(34) "The DSN string ended unexpectedly." } }

【问题讨论】:

    标签: php sql-server pdo sqlsrv


    【解决方案1】:

    我相信上面的 dsn 会引发错误,因为它缺少数据库名称。

    $ebilling = new PDO('sqlsrv:'.$myHost, $myUser, $myPass);

    您应该在第一部分中指定您的数据库名称以及您的主机。

    即:$ebilling = new PDO("sqlsrv:Server=$myHost;database=$myDatabase", $myUser, $myPass);

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2015-09-16
      • 2016-11-13
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多