Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP连接到MSSQL时出错_Php_Sql Server_Pdo_Odbc_Sqlsrv - Fatal编程技术网

使用PHP连接到MSSQL时出错

使用PHP连接到MSSQL时出错,php,sql-server,pdo,odbc,sqlsrv,Php,Sql Server,Pdo,Odbc,Sqlsrv,我收到如下错误: PHP致命错误:未捕获异常“PDOException”和消息 'SQLSTATE[08001]:[Microsoft][ODBC驱动程序11 for SQL Server]SQL Server 网络接口:连接字符串无效[87]。' 我的代码如下: $this->link = new PDO( "sqlsrv:server=$this->serverName:$this->port;Database=$this->db",

我收到如下错误:

PHP致命错误:未捕获异常“PDOException”和消息 'SQLSTATE[08001]:[Microsoft][ODBC驱动程序11 for SQL Server]SQL Server 网络接口:连接字符串无效[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"
我在Apache2.4.12和PHP5.5.24中使用XAMMP(它们都是x86)。我有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。请注意花括号,它们允许类变量