« Linux 電源管理 | 首頁 | 陳柏霖「睡的不醒人世」 »

2005年07月21日

FreeTDS @ Trustix 實戰備忘

最近許多網友在問 FreeTDSTrustix Linux 上的使用問題, 索性自己也弄個環境來試試, 沒想到這一試就試了兩天, 搞了一個頭好幾個大...

建置測試環境:

取得 Trustix Linux ISO 檔:

http://ftp.isu.edu.tw/pub/Linux/Trustix/releases/trustix-2.2/iso/

安裝 Trustix Linux:

只勾選基本套件, 安裝內容不到 400MB, 咻~ 一下就裝好了 :)

vi /etc/sshd_config --> PermitRootLogin yes (讓 root 可以遠端 ssh 登入)
chkconfig sshd on
service sshd start

vi /etc/locales.conf --> 找到 # zh_TW BIG5, 把註解符號 ( # ) 拿掉
locales-gen (讓系統 locale 支援 zh_TW 繁體中文)

安裝 FreeTDS:

 ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib && make && make install

安裝 Apache HTTP Server:

http://apache.cdpa.nsysu.edu.tw/httpd/httpd-2.0.54.tar.bz2

./configure --prefix=/usr/local/httpd --enable-so --enable-modules=so && make && make install

安裝 PHP:

http://tw2.php.net/get/php-4.4.0.tar.bz2/from/tw2.php.net/mirror

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-sybase=/usr/local/freetds && make && make install

cp php.ini-dist /usr/local/php/lib/php.ini

FreeTDS tsql 連結 MS-SQL Server 2000 測試結果:

./tsql -H <ip> -p 1433 -U sa

不管 LANG 設定為何, 皆能顯示中文資料.

./tsql -S <serv> -U sa

當 freetds.conf [serv] 區塊設有 tds version = 8.0 時, 需 export LANG=zh_TW 才能顯示中文資料; 若無 tds version 設定, 則不管 LANG 設定為何, 皆能顯示中文資料.

PHP mssql_connect() 連結 MS-SQL Server 2000 測試結果:

PHP configure 參數為: --with-mssql 時, 無法連結 MS-SQL 資料庫. (Unable to connect to server)

PHP configure 參數為: --with-sybase 時, 只能以 IP 連結, 使用 server_name 時會 hang 住, 除非在 /etc/hosts 加入 server_name 和其對應 IP. 看來它並不會去讀取 freetds.conf 設定檔 :( 此外, query 的資料有中文內容時, 會出現 Some character could not be converted into client's character set 的警告訊息. 雖然可以在 php.ini 設定 error_reporting = E_ERROR 讓它不顯示警告訊息, 不過中文字還是會變成問號...

若 PHP configure 參數: --with-mssql 和 --with-sybase 都指向 freetds 路徑, 執行時會在 httpd error_log 出現 duplicate name 的錯誤訊息, 其餘症狀同上述 --with-sybase 部份.


後記:

看來 FreeTDS 似乎在 Red Hat / Fedora 平台上比較正常些...

雖然沒能測出如何在 Trustix 平台以 PHP 透過 FreeTDS 讀出並顯示中文資料, 但至少又認識了一個不錯的 Linux 套件.

小而美的 Trustix Linux 真的挺適合拿來當 Linux Server 或拿來做實驗, 我已經喜歡上它了 :P

其實 PHP 連結 MS-SQL Server 還有許多解決方案, 像 ADODB、new COM("ADODB.Connection")、ASP on Linux, 再不然就乖乖的用 IIS + ASP 吧...

順帶一提, Firefox 1.0.6 中/英文版已經在 2005/07/20 同步推出囉!


延伸閱讀:

Posted by Jamyy at 2005年07月21日 19:32

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/104

Comments

感謝版主花時間測試,看來trustix 和freetds 的組合還是沒解的,因公司用的平台是trustix 和 centos為主,還沒在centos 上測,不過我想應該可以run 才是,再次感謝版主!!

Posted by: ken at 2005年07月22日 22:34

您客氣了, 託您的福, 我也從中學到不少東西 ^^
祝您順利成功~~

Posted by: Jamyy at 2005年07月26日 14:59