freetdsからperlでsybaseとmssqlにアクセス
3433 ワード
一、freetdsのインストール
freetds-patchedをダウンロードして解凍します.tar.gz
$ 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.1
make&sudo make install
環境変数の設定
二、修正/opt/local/freetds/etc/freetds.conf
ここを実践する
無効なようです(これは後のperlのコードに影響します)
テスト
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>
二、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
四、perlテストコード
1、mssqltest.pl
2、sybtest.pl
freetds-patchedをダウンロードして解凍します.tar.gz
$ 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.1
make&sudo make install
環境変数の設定
二、修正/opt/local/freetds/etc/freetds.conf
[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
ここを実践する
tds version = 5.0
無効なようです(これは後のperlのコードに影響します)
テスト
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>
二、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
四、perlテストコード
1、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]."
";
}
$dbh->disconnect;
2、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]."
";
}
$dbh->disconnect;