LPM: Re: DBI woes

David Pitts dpitts at mk.net
Wed Feb 23 21:40:14 CST 2000


Rich,
Here is what you have:
> $sth = $dbh->prepare("select day from reservation
> where ID = ?");
> foreach $ID (@conflicts) {
> $sth->execute($ID);
> ($day) = $sth->fetchrow_array;
> print "$day\n";
> }

I would have thought (and not having checked this on the computer), that it
would have been more like this:

$sql= <<EOT;
SELECT day
FROM reservation
WHERE ID = ?
EOT
$sth = $dbh ->prepare_cached($sql)  or die "\nSQL is $sql\n";
$sth->execute($ID);;
while ($sth->fetch){ print "$day\n" }

Although my sql is kinda new, so I may not have the SELECT statement exactly
correct.

Thanks,

David
David Pitts
President, Professional Consulting Services
www.dpitts.com
dpitts at mk.net
----- Original Message -----
From: Rich Bowen <rbowen at rcbowen.com>
To: perl mongers <lexington-pm-list at happyfunball.pm.org>
Sent: Wednesday, February 23, 2000 9:35 PM
Subject: LPM: DBI woes


> OK, I've been beating my head against this for about 30 minutes. Can one
> of you fine folks tell me the obvious thing that I'm missing?
>
> This:
>
> foreach $ID (@conflicts) {
> $sth = $dbh->prepare("select day from reservation
> where ID = $ID");
> $sth->execute;
> ($day) = $sth->fetchrow_array;
> print "$day\n";
> }
>
> is printing a list of days, as expected.
>
> However, this (which is, in theory, better)
>
>
> $sth = $dbh->prepare("select day from reservation
> where ID = ?");
> foreach $ID (@conflicts) {
> $sth->execute($ID);
> ($day) = $sth->fetchrow_array;
> print "$day\n";
> }
>
> Only prints every other record.
>
> Am I missing something obvious? I'd like to do it the faster way, but
> it's giving me bogus results.
>
> Rich
> --
> http://www.ApacheUnleashed.com/
> Lexington Perl Mongers - http://lexington.pm.org/
> PGP Key - http://www.rcbowen.com/pgp.txt
>




More information about the Lexington-pm mailing list