- 论坛徽章:
- 0
|
[quote]The DBI itself does not mandate or require any particular language to be used; it is language indepe ...
[size=2][color=#999999]akwhole 发表于 2011-08-03 15:58[/color] [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=21287909&ptid=3576313][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url][/size][/quote]
意思是说,DBI接口不依赖于具体的数据库类型,它下面有DBD::Oracle, DBD::Mysql来处理这些数据库的差异。
对于DBI来说,它只管把接收到的SQL语句作为一个字符变量,来执行prepare和do操作。
my $dsn = "dbi:Oracle:$tns";
my $dbh = DBI->connect( $dsn, $user, $passwd, {RaiseError => 0} );
my $sql = "SELECT version FROM product_component_version WHERE product LIKE '%Oracle%' ";
my $sth = $dbh->prepare( $sql );
$sth->execute( );
数据库的差异由创建$dbh时,由$dsn指定,到了后面的$sth,就只管执行SQL。 |
|