错误连接MSSQL使用PHP
问题描述:
我收到了如下错误:错误连接MSSQL使用PHP
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. '
我的代码如下:
$this->link = new PDO(
"sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
"$this->uid",
"$this->pwd"
);
我希望有人可以告诉我是什么原因造成这个错误。在此之前,我使用dblib
而不是sqlsrv
。
"dblib:host=$this->serverName:$this->port;dbname=$this->db"
我在Apache 2.4.12和PHP 5.5.24(它们都是x86)上使用XAMMP。我有php_pdo_sqlsrv_55_ts.dll和php_sqlsrv_55_ts.dll。我也为SQL Server-x64使用Microsoft ODBC驱动程序11。
答
将其更改为:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
SQL Server的默认端口是1433。注意大括号,它们允许类变量。