問(wèn)題描述
我正在連接到外部 MSSQL 數(shù)據(jù)庫(kù)以從 PHP55/osx 導(dǎo)出,但遇到了奇怪的問(wèn)題.
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)
但來(lái)自 CLI 的連接工作正常
but connection from CLI works correcty
tsql -S 主機(jī)名 -U 用戶(hù) -P pass -L 數(shù)據(jù)庫(kù)名:
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
有什么想法嗎?我?guī)缀鯂L試過(guò)任何東西,連接到主機(jī)名、IP、帶和不帶端口、實(shí)例名稱(chēng)、另一個(gè)用戶(hù)、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
推薦答案
檢查這些:
在您的磁盤(pán)上找到 freetds.conf.它可能存在于多個(gè)地方,tsql 使用一個(gè),而 PHP 使用另一個(gè).最好的方法是將它們符號(hào)鏈接到一個(gè)公共文件中并對(duì)其進(jìn)行測(cè)試.請(qǐng)注意,該文件的常見(jiàn)位置是/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 文件中應(yīng)該有一個(gè) [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
客戶(hù)端字符集 = UTF-8
client charset = UTF-8
當(dāng)然,我希望您已經(jīng)使用 phpinfo() 檢查過(guò) PHP 加載了哪個(gè)驅(qū)動(dòng)程序:mssql、sqlsrv 或 dblib
Of course, I expect that you already checked which driver is loaded by PHP with phpinfo(): mssql, sqlsrv or dblib
這篇關(guān)于PHP PDO_mssql SQLSTATE[01002] Adaptive Server 連接失敗(嚴(yán)重性 9)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!