Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Looping with DBI

by Kanji (Parson)
on Jun 30, 2002 at 11:27 UTC ( [id://178354]=note: print w/replies, xml ) Need Help??


in reply to Re: Looping with DBI
in thread [untitled node, ID 178308]

If you're going to go through the trouble of using bind variables, why not move the second prepare outside the while? That way you avoid needless re-prepareing of the same statement on every iteration of the loop...

my $sth_news = $dbh->prepare(" SELECT id, body FROM news "); $sth_news->execute; $sth_news->bind_columns(\my $news_id,\my $news_body); my $sth_comments = $dbh->prepare(" SELECT COUNT(id) FROM comments WHERE id = ? "); while ($sth_news->fetch) { $sth_comments->execute($news_id); $sth_comments->bind_columns(\my $comments); $sth_comments->fetch; print "$news_id, $news_body, $comments"; }

    --k.


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://178354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found