代码如下:
复制代码
代码如下:
#!/bin/perl
use
DBI
#
Connect
to
target
DB
my
$dbh
=
DBI->connect("DBI:mysql:database=eyglehost=localhost","username","password",
{'RaiseError'
=>
1})
#
Insert
one
row
my
$rows
=
$dbh->do("INSERT
INTO
test
(id,
name)
VALUES
(1,
'eygle')")
#
query
my
$sqr
=
$dbh->prepare("SELECT
name
FROM
test")
$sqr->execute()
while(my
$ref
=
$sqr->fetchrow_hashref())
{
"$ref->{'name'}n"
}
$dbh->disconnect()
Step 1:安装FreeTDS模块这是个Sybase的Client端软件,必须安装。可以从www.freetds.org/software.html上下载源文件安装程序FreeTDS-stable.tgz来进行安装。
可能需要在系统上增加如下的环境变量: LD_LIBRARY_PATH中增加/usr/4lib
安装步骤:
安装FreeTDS
#gunzip FreeTDS-stable.tgz
#tar xvf FreeTDS-stable.tar
#cd freetds-0.63 目前版本是0.63
#./configure --prefix=/usr/local/freetds
#make
#make install
配置FreeTDS
#cd /usr/local/freetds/etc
修改配置文件freetds.conf,在其中增加需要连接的Sybase服务器相关信息,如下:
[TEST]
host=192.168.0.1
port=4100
tds version = 5.0
Step 2:安装和配置DBI-1.50 、DBD-Sybase-1.07 、sybperl-2.18等Module即可。可以从www.cpan.org上下载。
修改CONFIG文件SYBASE配置路径,将其设置为/usr/local/freetds
设置环境变量:
SYBASE=/usr/local/freetds
export SYBASE
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
export LD_LIBRARY_PATH
# Fix dbdimp.c before compiling or you will get an error:
>dbdimp.c:800: error: 'BLK_VERSION_150' undeclared (first use in this function)
>dbdimp.c:800: error: (Each undeclared identifier is reported only once
>dbdimp.c:800: error: for each function it appears in.)
# This is really a FreeTDS bug - they define the CS_VERSION_1xx symbols, but not the corresponding BLK_VERSION_xxx symbols.
Edit dbdimp.c and add
vi /usr/src/DBD-Sybase-1.08/dbdimp.c
#define BLK_VERSION_150 BLK_VERSION_100
#define BLK_VERSION_125 BLK_VERSION_100
#define BLK_VERSION_120 BLK_VERSION_100
vi /download/sybperl-2.19/CTlib/CTlib.c
#define BLK_VERSION_150 BLK_VERSION_100
#define BLK_VERSION_125 BLK_VERSION_100
#define BLK_VERSION_120 BLK_VERSION_100
连接示例:
#!/usr/bin/perl
#
use DBI
use Sybase::DBlib
Sybase::DBlib::DBSETLCHARSET("eucgb")
Sybase::DBlib::DBSETLNATLANG("chinese")
$dbh = Sybase::DBlib->new('root', '1234', 'TEST')
$dbh->dbcmd("select * from test.name")
$dbh->dbsqlexec
while($dbh->dbresults != NO_MORE_RESULTS) {
while(@data = $dbh->dbnextrow) {
print @data,"\n"
}
}
$dbh->dbclose
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)