問題描述
我正在連接到外部 MSSQL 數據庫以從 PHP55/osx 導出,但遇到了奇怪的問題.
I'm connecting to external MSSQL database for exports from PHP55/osx and I have wierd issue.
代碼:
new PDO("dblib:host={$hostname};dbname={$dbname}", $user, $pass);
拋出:
SQLSTATE[01002] Adaptive Server connection failed (severity 9)
但來自 CLI 的連接工作正常
but connection from CLI works correcty
tsql -S 主機名 -U 用戶 -P pass -L 數據庫名:
locale is "cs_CZ.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
freetds.conf:
[hostname]
host = ipaddress
port = 1433
tds version = 8.0
tsql -C:
Version: freetds v0.91
freetds.conf directory: /usr/local/Cellar/freetds/0.91/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 7.1
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
有什么想法嗎?我幾乎嘗試過任何東西,連接到主機名、IP、帶和不帶端口、實例名稱、另一個用戶、TDS 版本 7.0、7.1、7.2、8.0,重新安裝 php 和 freetds
Any ideas? I have tried alomost anything, connect to hostname, ip, with and without port, to instance name, another user, TDS versions 7.0,7.1,7.2,8.0, reinstall php and freetds
推薦答案
檢查這些:
在您的磁盤上找到 freetds.conf.它可能存在于多個地方,tsql 使用一個,而 PHP 使用另一個.最好的方法是將它們符號鏈接到一個公共文件中并對其進行測試.請注意,該文件的常見位置是/etc/或/usr/local/etc/旁邊的 ~/.freetds.conf
locate freetds.conf on your disk. It is possible it exists in several places and tsql uses one while PHP used another one. Best is to symlink them into one common file and test on that. Note that a common place for that file is ~/.freetds.conf beside /etc/ or /usr/local/etc/
在您的 freetds.conf 文件中應該有一個 [global] 部分.把這些行放在那里:
there should be a [global] section on your freetds.conf file. Put there these lines :
tds 版本 = 8.0
tds version = 8.0
文字大小 = 20971520
text size = 20971520
客戶端字符集 = UTF-8
client charset = UTF-8
當然,我希望您已經使用 phpinfo() 檢查過 PHP 加載了哪個驅動程序:mssql、sqlsrv 或 dblib
Of course, I expect that you already checked which driver is loaded by PHP with phpinfo(): mssql, sqlsrv or dblib
這篇關于PHP PDO_mssql SQLSTATE[01002] Adaptive Server 連接失敗(嚴重性 9)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!