简体   繁体   English

SQLSRV PDO DSN字符串结尾

[英]SQLSRV PDO DSN String Ended

I've been fighting to get mssql PDO extension working in PHP 4 before realizing that it doesn't. 我一直在努力让mssql PDO扩展在PHP 4中工作,然后才意识到事实并非如此。 So I've managed to get the sqlsrv extension loaded on Windows Server 2012 and it seems to be finding the driver and has loaded it into PHP corrected however it seems that my DSN isn't correct and I can't figure out why... Here is my code for connecting... 因此,我设法在Windows Server 2012上加载了sqlsrv扩展名,它似乎正在查找驱动程序并将其加载到PHP中,但更正了它,但似乎我的DSN不正确,我不知道为什么。这是我连接的代码...

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

And here is the error I'm getting on my page... 这是我在页面上遇到的错误...

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." } }

I believe the dsn above raise an error because it misses a database name. 我相信上面的dsn会引发错误,因为它缺少数据库名称。

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

You should specify your database name along with your host as in the first part. 您应该像在第一部分中一样指定数据库名称以及主机。

ie: $ebilling = new PDO("sqlsrv:Server=$myHost;database=$myDatabase", $myUser, $myPass); 即:$ ebilling =新的PDO(“ sqlsrv:Server = $ myHost; database = $ myDatabase”,$ myUser,$ myPass);

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM