Ubuntu

php5-mssql / freetds : 可以與 tsql 連接,不能與 php5-mssql

  • July 13, 2010

我正在嘗試使用 php5-mssql 為 php 開發設置一個 Ubuntu 工作站。首先,我編譯了 freetds-nightly 0.8.3(帶有 –enable-msdblib )並將其安裝到 /usr/local/freetds ,將包中的標頭檔複製到 /usr/local/freetds/include

然後,我用 apt-get source php5 抓取了 php5 源碼,並編譯了 mssql 擴展如下:

phpize
cd ext/mssql
./configure --with-mssql=/usr/local/freetds
make
sudo install

這將 mssql.so 放入我的 php 擴展目錄中,並且 php 正在載入擴展。畢竟,我在 /usr/local/freetds/etc/freetds.conf 中添加了我的伺服器:

[global]
   tds version = 7.0
   dump file = /tmp/freetds.log
   text size = 64512

[db-02]
host = XXXXX
port = 1433
tds version = 7.0

首先,我想使用 tds 8.0,但任何高於 7.1 的值都會被忽略,這是一個意外,因為我的 mac 上的 freetds(使用 +mssql 由 macports 建構)在較舊時執行 8.0。(0.8.2 我認為)

無論如何,有了這個,我可以用 /usr/local/freetds/bin/tsql 漂亮地連接到我的伺服器。不適用於 php5-mssql ..

這是 freetds.log 的一些輸出(這都是失敗的嘗試)

log.c:196:Starting log file for FreeTDS 0.83.dev.20100710
   on 2010-07-13 11:17:23 with debug flags 0x4fff.
iconv.c:337:tds_iconv_open(0x91d3a98, UTF-8)
iconv.c:197:local name for ISO-8859-1 is ISO-8859-1
iconv.c:197:local name for UTF-8 is UTF-8
iconv.c:197:local name for UCS-2LE is UCS-2LE
iconv.c:197:local name for UCS-2BE is UCS-2BE
iconv.c:365:setting up conversions for client charset "UTF-8"
iconv.c:367:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:408:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:411:tds_iconv_open: done
net.c:225:Connecting to XXXX port 1433 (TDS version 7.0)
net.c:281:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:321:tds_open_socket() succeeded
util.c:156:Changed query state from DEAD to IDLE
login.c:771:quietly sending TDS 7+ login packet
token.c:328:tds_process_login_tokens()
net.c:608:Received header
0000 04 01 00 78 00 49 01 00-                        |...x.I..|

net.c:662:Received packet
0000 04 01 00 78 00 49 01 00-aa 64 00 18 48 00 00 01 |...x.I.. .d..H...|
0010 0e 1f 00 4c 00 6f 00 67-00 69 00 6e 00 20 00 66 |...L.o.g .i.n. .f|
0020 00 61 00 69 00 6c 00 65-00 64 00 20 00 66 00 6f |.a.i.l.e .d. .f.o|
0030 00 72 00 20 00 75 00 73-00 65 00 72 00 20 00 27 |.r. .u.s .e.r. .'|
0040 00 63 00 61 00 6c 00 76-00 69 00 6e 00 27 00 2e |.X.X.X.X .X.X.'..|
0050 00 0d 4e 00 45 00 54 00-4d 00 49 00 4e 00 49 00 |..Y.Y.Y. Y.Y.Y.Y.|
0060 4e 00 47 00 44 00 41 00-54 00 41 00 00 01 00 fd |Y.Y.D.A. T.A.....|
0070 02 00 00 00 00 00 00 00-                        |........|

token.c:337:looking for login token, got  aa(ERROR)
token.c:122:tds_process_default_tokens() marker is aa(ERROR)
token.c:2710:tds_process_msg() reading message 18456 from server
token.c:2783:tds_process_msg() calling client msg handler
dbutil.c:85:_dblib_handle_info_message(0x90180e8, 0x91d3a98, 0xbf8f56d0)
dbutil.c:86:msgno 18456: "Login failed for user 'XXXX'."
token.c:2796:tds_process_msg() returning TDS_SUCCEED
token.c:337:looking for login token, got  fd(DONE)
token.c:122:tds_process_default_tokens() marker is fd(DONE)
token.c:2461:tds_process_end: more_results = 0
       was_cancelled = 0
       error = 1
       done_count_valid = 0
token.c:2477:tds_process_end() state set to TDS_IDLE
token.c:2492:                rows_affected = 0
token.c:437:tds_process_login_tokens() returning TDS_FAIL
login.c:462:login packet accepted
util.c:156:Changed query state from IDLE to DEAD
util.c:331:tdserror(0x90180e8, 0x91d3a98, 20002, 0)
dblib.c:7861:dbperror(0x91d3378, 20002, 0)
dblib.c:7913:20002: "Adaptive Server connection failed"
dblib.c:7934:"Adaptive Server connection failed", client returns 2 (INT_CANCEL)
util.c:361:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:384:tdserror: returning TDS_INT_CANCEL(2)
dblib.c:1415:dbclose(0x91d3378)
dblib.c:258:dblib_del_connection(0x997340, 0x91d3a98)
mem.c:615:tds_free_all_results()
dblib.c:305:dblib_release_tds_ctx(1)
dblib.c:5828:dbfreebuf(0x91d3378)
dblib.c:724:dbloginfree(0x91d2f90)
dblib.c:3985:dbsetlogintime(5)
dblib.c:3944:dbsettime(60)
dblib.c:698:dblogin(void)
dblib.c:4890:dberrhandle(0x81a1fd0)
dblib.c:4909:dbmsghandle(0x81a35d0)
dblib.c:746:dbsetlname(0x91d2f90, UTF-8, 10)
dblib.c:746:dbsetlname(0x91d2f90, PHP 5, 5)
dblib.c:1121:dbopen(0x91d2f90, 0x0, [microsoft])

(相同的憑據讓我使用 tsql )

任何幫助是極大的讚賞。

謝謝,安德魯

ps: 一些 tsql -C 輸出

Compile-time settings (established with the "configure" script)
                           Version: freetds v0.83.dev.20100710
            freetds.conf directory: /usr/local/freetds/etc
    MS db-lib source compatibility: yes
       Sybase binary compatibility: no
                     Thread safety: yes
                     iconv library: yes
                       TDS version: 5.0
                             iODBC: no
                          unixodbc: yes

解決了。應該使用穩定版本.. 0.8.2 支持 tds 8.0,0.8.3 不支持。呃。

順便說一句,這仍然沒有解釋為什麼我能夠使用 tsql 連接到我的 mssql 伺服器,使用協議 7.1,但不能使用 php5-mssql。

引用自:https://serverfault.com/questions/159889