[英]Error connecting to MSSQL using PHP
I am receiving an error as below: 我收到如下错误:
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].
PHP致命错误:消息为'SQLSTATE [08001]的未捕获异常'PDOException':[Microsoft] [SQL Server的ODBC驱动程序11] SQL Server网络接口:连接字符串无效[87]。 '
“
My codes are as follow: 我的代码如下:
$this->link = new PDO(
"sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
"$this->uid",
"$this->pwd"
);
I wish someone can enlighten me on what is causing this error. 我希望有人能启发我导致此错误的原因。 Before that I was using
dblib
instead of sqlsrv
. 在此之前,我用
dblib
,而不是sqlsrv
。
"dblib:host=$this->serverName:$this->port;dbname=$this->db"
I am using XAMMP with Apache 2.4.12 and PHP 5.5.24 (they are all x86). 我将XAMMP与Apache 2.4.12和PHP 5.5.24一起使用(它们都是x86)。 I have php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll.
我有php_pdo_sqlsrv_55_ts.dll和php_sqlsrv_55_ts.dll。 I am also using Microsoft ODBC Driver 11 for SQL Server-x64.
我也将Microsoft ODBC Driver 11用于SQL Server-x64。
Change it to: 更改为:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
The default SQL Server port is 1433. Note the curly brackets, they allow for class variables. SQL Server的默认端口为1433。请注意大括号,它们允许使用类变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.