The only comment I would add on this is that what you will do may slow your program down. I mean if you execute a query inside a loop that has say 100,000 records, you'll be executing a query 100,000 time inside that loop.
If the second query will be referencing the same index in a table, I would recommend creating a hash for the entire second dbi execute prior to executing the first query and performing the loop. This way, you're simply reference the hash for the value instead of performing all those queries. This may not work for what you need, but I thought it would be worth noting.
example:
## ASSUMED CONNECTION ESTABLISHED ## # CREATE HASH FOR REFERENCE $sth = $dbh->prepare("select report_id, name from reportindex"); $sth->execute(); while ($ref = $sth->fetchrow_hashref()) { $reportIndex{"R$ref->{'report_id'}"} = $ref->{'name'}; } $sth->finish() unless (! $sth); $sth = $dbh->prepare("select reportindex_id from favorite_reports"); $sth->execute(); while ($ref = $sth->fetchrow_hashref()) { # REFERENCE HASH INSTEAD OF CALLING SECOND QUERY print "I like the report: ". $reportIndex{"R$ref->{'reportindex_id +'}"}; } $sth->finish() unless (! $sth);
Hope this helps.
In reply to Re: dbi question
by FitTrend
in thread dbi question
by philosophia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |