develooper Front page | perl.dbi.users | Postings from February 2001

How to print a table field in DBI?

Thread Next
From:
David Jacobowitz
Date:
February 22, 2001 17:48
Subject:
How to print a table field in DBI?
Message ID:
F40gRGkQ6mBySsxVY6000006a42@hotmail.com
Hi All,

Spend few hours trying to figureout a way to print my field name with the 
returned field value without any success.  Looked in the websites but no 
clue.  Below is my code can anyone modify the code so it will print 
field_name_in_mysql_table and field_values that is in mysql?  I have 5 
fields in my table.

.
.
.
my $dbh = DBI->connect ( "DBI:mysql:test:localhost", "test", "*******",
{
        PrintError => 0,
        RaiseError => 0
}) or die "Can't connect to the database: $DBI::errstr\n";

my $sth = $dbh->prepare( "
SELECT * FROM incu_management WHERE person_id=1001 " )
        or die "can't preare SQL statement: $DBI::errstr\n";

$sth->execute ();

while ($ref = $sth->fetchrow_hashref) {
    foreach $key (keys %{$ref}) {
	print “$field_name(need help here)------ $ref->{$key}, ”;
    }
    print "\n";
}

$dbh->disconnect;

Thanks in advance for any help.

David

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About