|
|
|
[
来路:21kn.com 时间:2007-7-8 16:29:09
点击: ] |
|
|
|
|
|
我们使用DBI之前首先需要声明:
#!/usr/bin/perl -w
use DBI;
我们有两种方法可以建立PERL与数据库之间的连接:
#!/usr/bin/perl -w
use DBI;
#建立与数据库的连接,第4个参数标明数据库类型
= DBI->connect( 'connection_string', 'username', 'password', 'mSQL' );
if ( !defined ) {
die "Cannot do \->connect: ::errstr\n";
}
通过这种方法,返回一个数据库句柄。这是一种常用的用法,另外一种方法返回“驱动程序句柄”:
#!/usr/bin/perl -w
use DBI;
= DBI->install_driver( 'mSQL' );
if ( !defined ) {
die "Cannot load driver: $!\n";
}
这种方法多用来检查是否系统中是否存在某种驱动程序。
以下是一些利用DBI处理数据库的历程:
1、打开连接(数据库)已经关闭
#!/usr/bin/perl -w
#
# (c)1996 Alligator Descartes <descarte@hermetica.com>
#
# inout.pl: Connects and disconnects from a specified database
use DBI;
if ( $#ARGV < 0 ) {
die "Usage: inout.pl <Database String> <Database Vendor>\n";
}
# Create new database handle. If we can't connect, die()
= DBI->connect( '', , '', );
if ( !defined ) {
die "Cannot connect to mSQL server: ::errstr\n";
}
# Disconnect from the database
->disconnect;
exit;
|
|
|
::::站长友情提示:多花一分钟学点什么都好::::
|
|
|
|
|
|
|
|
|
|
|
|
=
= 免责声明 = = |
|
①
欢迎转载我网所刊信息,请注明“来源:E天下网络”。
② 凡本网注明“来源:XXX(非E天下网络)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如因作品内容、版权和其它问题需要同本网联系的,请在30日内进行。
※联系方式:Airtofly@163.com |
|
|