使用 PHP 连接到 MSSQL 时出错
Error connecting to MSSQL using 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"
我将 XAMMP 与 Apache 2.4.12 和 PHP 5.5.24(它们都是 x86)一起使用。我有 php_pdo_sqlsrv_55_ts.dll 和 php_sqlsrv_55_ts.dll。我也在为 SQL Server-x64 使用 Microsoft ODBC Driver 11。
改为:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
默认的 SQL 服务器端口是 1433。注意大括号,它们允许 class 变量。
我收到如下错误:
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"
我将 XAMMP 与 Apache 2.4.12 和 PHP 5.5.24(它们都是 x86)一起使用。我有 php_pdo_sqlsrv_55_ts.dll 和 php_sqlsrv_55_ts.dll。我也在为 SQL Server-x64 使用 Microsoft ODBC Driver 11。
改为:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
默认的 SQL 服务器端口是 1433。注意大括号,它们允许 class 变量。