query inside a loop

Sham Prasad <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Hi all,

I have a script which reads in a file containing ID's into an array.
Then i am using mysql query to query for each ID one by one.but i am
getting a syntax error. i want to know is it possible to pass variable
to a query? i am pasting the script along with this mail please have
 a look.

use DBI;
open F1, "filepath";
$"=",";
@bug = <F1>;
close F1;
for(my $i=0;$i<=@bug;$i++)
{
$id = $bug[$i];
my $dbh =
DBI->connect("DBI:mysql:database=Pbugs;host=appletest","username","password",{'RaiseError'
=> 1});
my $sth = $dbh->prepare("select bug_id,short_desc,bug_status from bugs where
bug_id=$id") or die "cant prepare statement";
$sth->execute();
print "$sth";
while(my @row = $sth->fetchrow_array()){
open FILE, "filepath";
@arr=<FILE>;
splice(@arr,2,1);
open FILE, ">filepath";
$" = ",";
print (FILE @arr);
chop(@arr);
print FILE "@row\n";
close(FILE);
}
}
$sth->finish();
$dbh->disconnect();

can anyone tell what changes should i make in the script? i am using a
variable in the query to auery for all the ID's.

Thanking you
sham
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.