我正在尝试使用 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(由 macports 使用 +mssql 构建)使用的是 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
答案1
解决了。应该使用稳定版本。0.8.2 支持 tds 8.0,0.8.3 不支持。呃。
顺便说一句,这仍然不能解释为什么我能够使用协议 7.1 通过 tsql 连接到我的 mssql 服务器,但不能使用 php5-mssql。