I have this script that will read a Table. The table has 2 fields: Draw date (Primary Key), Draw Number (an Index). The table is MYSql in MYISAM format.
I copied the script below from a book to get the database to open then read the table. If I understand correctly, gthis script reads the entire table into memory then extracts thae rows based on fetchrow.
We come from the MicroFocus Icobol platform that uses similar isam files. How would you just Read one record at a time (by either primary key or the other index) without storing them all in memory, do what you have to do with it, then read the next record?
# Connect To The Database my $dbh = DBI->connect("DBI:mysql:masslottery_db", "root", "system1"); die "Connect to masslottery_db failed: " . DBI->errstr() unless $dbh; print "connect to masslottery_db successful!\n"; #Prepare The Query To Get Data From Table Dailymf #$dbh Is Called The Database Handler my $sth = $dbh->prepare("Select dailymf_drawdate,dailymf_number FROM d +ailymf") or die "Prepare For Dailymf Failed: " . $dbh->errstr( +); #Execute The Query #$sth Is Called The State Handler $sth->execute() or die "Execute For Dailymf Failed: " . $sth->errstr(); #Read (loop) Each Row (record) and Print It while (($dailymf_drawdate, $dailymf_number) = $sth->fetchrow()) { print "$dailymf_drawdate : $dailymf_number\n"; }
Thanks again for the help.
In reply to Reading A TAble by PerceptiveJohn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |