how to get the column names and the values of them in select statement.

I have a package like this named ADB.pm
package 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; }
and perl file adb.pl like this
#!/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";
when execute adb.pl it displays the table results blidly.

I need to get the column names also with the respective values. Can u please tell me which modification i need to do in the code

results what i am getting are like this

1 admin admin 1 3 3
2 demouser 111111 1 1 1

i want the column names to be print for them.

In reply to Small Doubt regarding DB Select by koti688

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.