1、安裝freetdssql
下載並解壓freetds-patched.tar.gzshell
$ tar zxvf freetds-patched.tar.gz測試
./configure --prefix=/opt/local/freetds --enable-msdblib --enable-sybase-compat --with-gnu-ld --enable-shared --enable-static --with-unixodbc=/usr --with-tdsver=7.1fetch
make&sudo make installthis
設置好環境變量spa
2、修改/opt/local/freetds/etc/freetds.confdebug
[global] # TDS protocol version ; tds version = 4.2 # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system) ; dump file = /tmp/freetds.log ; debug flags = 0xffff # Command and connection timeouts ; timeout = 10 ; connect timeout = 10 # If you get out-of-memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # Try setting 'text size' to a more reasonable limit text size = 64512 client charset = UTF-8 # A typical Sybase server [egServer50] host = localhost port = 5000 tds version = 5.0 # A typical Microsoft server [egServer70] host = 192.168.0.177 port = 1433 tds version = 7.0
經實踐這裏unix
tds version = 5.0
貌似無效(這會影響後面perl的代碼)code
測試server
l$ tsql -SegServer70 -Umymotif -Pwxwpxh
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
mssql經過
$ tsql -S egServer50 -U mymotif -Pwxwpxh
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
sybase出錯
$ TDSVER=5.0 tsql -SegServer50 -Umymotif -Pwxwpxh
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
2、安裝DBD-Sybase
wget http://www.peppler.org/downloads/DBD-Sybase-1.15.tar.gz
獲取源代碼
export SYBASE=/opt/local/freetds (注意不是SYBASE=/opt/sybase)
接着就是安裝perl模塊的標準動做
perl Makefile.PL
make
make test
make install
4、perl測試代碼
一、mssqltest.pl
#!/usr/bin/perl use DBI; use DBD::Sybase; $dbname="mymotif"; $user="mymotif"; $passwd="wxwpxh"; #SQLSERVER 字串對應於 /opt/local/freetds/etc/freetds.conf 裏面的 [SQLSERVER] $dsn = "DBI:Sybase:server=egServer70;database=$dbname"; $dbh = DBI->connect($dsn,$user,$passwd) or die "can't connect to database : $DBI::errstr"; $sth=$dbh->prepare("select * from STUDENT"); $sth->execute; while (@recs=$sth->fetchrow_array) { print $recs[0].":".$recs[1].":".$recs[2]."\n"; } $dbh->disconnect;
二、sybtest.pl
#!/usr/bin/perl use DBI; use DBD::Sybase; $dbname="testdb"; $user="mymotif"; $passwd="wxwpxh"; #egServer50 字串對應於 /opt/local/freetds/etc/freetds.conf 裏面的 [egServer50] $ENV{TDSVER} = "5.0"; $dsn = "DBI:Sybase:server=egServer50;database=$dbname"; $dbh = DBI->connect($dsn,$user,$passwd) or die "can't connect to database : $DBI::errstr"; $sth=$dbh->prepare("select * from STUDENT"); $sth->execute; while (@recs=$sth->fetchrow_array) { print $recs[0].":".$recs[1].":".$recs[2]."\n"; } $dbh->disconnect;