Great, the uppercase in $sth->{NUM_OF_FIELDS} works. Now I can start to
learn perl. Any advice on where could I find a good source for beginner on
the web? Thank you very much.
>From: ds <[EMAIL PROTECTED]>
>To: Andy Cheng <[EMAIL PROTECTED]>
>CC: [EMAIL PROTECTED]
>Subject: Re: Mysql installation. Help!
>Date: 11 Mar 2002 19:41:08 +0000
>
>
>I don't understand the code. I copy it from a book. I am trying to print
>out
>the records returned from a query. I have a table named client in database
>andy. The table has 2 records. When I run the above code, I have 2 blank
>lines return. Could any one tell me what the problem is? Where could I
>find better documentation on DBI::DBD::mysql stuff for beginner? man
>DBD::mysql is difficult to understand. Thanks again for the info.
>
>#!/usr/bin/perl
>
>use DBI;
>$dbh=DBI->connect('DBI:mysql:andy');
>my $query="select * from client";
>my $sth=$dbh->prepare($query) or die "cann't prepare".$dbh->errstr."\n";
>$sth->execute;
>my $rows;
>while(@row=$sth->fetchrow_array)
>{my $i;
>for $i (0..($sth->{num_of_fields}-1))
>{print "[".$row[$i]."]";}
>print("\n");
>}
>$sth->finish;
>$dbh->disconnect
>Hi,
>I'm not an expert in perl too, but i would correct your code to this:
>
>#!/usr/bin/perl
>
>use DBI;
>$dbh=DBI->connect('DBI:mysql:andy');
>my $query="select * from client";
>my $sth=$dbh->prepare($query) or die "cann't prepare".$dbh->errstr."\n";
>$sth->execute;
>my $rows;
>while(@row=$sth->fetchrow_array)
>{my $i;
>for $i (0..($sth->{NUM_OF_FIELDS}-1))
>{print "[".$row[$i]."]";}
>print("\n");
>}
>$sth->finish;
>$dbh->disconnect
>
>Note the uppercase in $sth->{NUM_OF_FIELDS}.
>Also remove the line "my $rows"... It's doing nothing there.
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php