and perl file adb.pl like thispackage ADB; use DBI; @ISA = ('Exporter'); @EXPORT_OK = ("Connection_check", "new","select_db"); sub new { my $class = shift; my $self = { _pf => shift, _db => shift, _host => shift, _port => shift, _user => shift, _pass => shift }; $dbh = Connection_check($self); #$self->{_dbh} = $dbh; bless $self, $class; return $self; } sub Connection_check { my($self ) = @_; $dsn = "DBI:$self->{_pf}:$self->{_db};$self->{_host};$self->{_port +}"; #$dsn = "DBI:mysql:database=$self->{_db};host=$self->{_host};port= +$self->{_port}"; $dbhc = DBI->connect($dsn,$self->{_user},$self->{_pass})or die "Un +able to connect: $DBI::errstr\n"; return ($dbhc) } ### Retrieving the Rows ######## sub select_db{ my ($obj,$sel) = @_; my $selnew = $dbh->prepare($sel); $selnew->execute or die "Unable to connect: $DBI::errstr\n"; my @AoA; my @FinArr; while (@AoA = $selnew->fetchrow_array) { push @FinArr, [@AoA]; } return @FinArr; }
when execute adb.pl it displays the table results blidly.#!/usr/bin/perl use DBI; use DBD::mysql; use Utils::ADB; $object = new ADB( "mysql","adb", "192.168.106.218", 3306, "root", "ro +ot"); my @records = $object -> select_db ("select * from users"); foreach $recRef (@records) { print join (" ", @$recRef),"\n"; } print "\n \n";
In reply to Small Doubt regarding DB Select by koti688
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |