If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > querying multiple times

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-05-10, 12:14
bob44 bob44 is offline
Registered User
 
Join Date: May 2010
Posts: 1
querying multiple times

Hi

I would like to run a query multiple times in a foreach loop passing different variables from an array into each query. The query works fine on its own, but doesn't in the foreach loop.

foreach (@array) {

my $sth2 = $dbh->prepare("SELECT ACCTID FROM data.csv WHERE ACCTID= ?");
$sth2->execute($_);

while (my $row2 = $sth2->fetchrow_hashref) {
push(@array2, $row2->{'ACCTID'});
}

$sth2->finish();

}

Any help would be much appreciated.
Reply With Quote
  #2 (permalink)  
Old 05-12-10, 09:04
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
The finish call is redundant, but aside from that, you'll have to tell us what error messages you're getting, and show your complete connection string and indicate what OS, DBMS, version of Perl you're using.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On