Perl Perform DB Operations
发布时间:2020-12-16 00:22:19 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl -w package PerformDBOperations; use strict; use English; use Carp; use DBI; my $dbHandle = 0; sub new { ? ? my $class = shift(@ARG); ? ? ?? ? ? my $self = {}; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $self-{
#!/usr/bin/perl -w package PerformDBOperations; use strict; use English; use Carp; use DBI; my $dbHandle = 0; sub new { ? ? my $class = shift(@ARG); ? ? ?? ? ? my $self = {}; ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $self->{_dbUserName} ?= undef; ? ? $self->{_dbPassword} ?= undef; ? ? $self->{_dbHandle} ? ?= $dbHandle; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bless ($self,$class); ? ? ? ?? ? ? return $self; ? ? ? ? ? ? ? ? ? } sub ConnectTo { ? ? ? ? my $self = shift; ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? $self->{_dbUserName} = shift; ? ? ? ? $self->{_dbPassword} = shift; ? ? ? ? my $password = $self->{_dbPassword};? ? ? ? ? my $username = $self->{_dbUserName}; ? ? ? ? ? ? ${$self->{_dbHandle}} = DBI->connect( "dbi:Oracle:",? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "$username",? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "$password" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ); ? ? ? ? if( !${$self->{_dbHandle}} ) ? ? ? ? { ? ? ? ? ? die ( "DB connection failed n".$DBI::errstr); ? ? ? ? } } sub DoSQLStatement { ? ? ? ? my $self = shift; ? ? ? ? my $sql = shift; ? ? ? ? my $sth = ${$self->{_dbHandle}}->prepare( $sql ); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if( !$sth ) ? ? ? ? { ? ? ? ? ? confess( "DB prepare failed:".${$self->{_dbHandle}}->errstr); ? ? ? ? } ? ? ? ? $sth->execute(); ? ? ? ?? ? ? ? ? return $sth; } 1;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |