You're sharing $sth -- create one for each query instead
(e.g., $sth1 and $sth2).
Each statement being executed at the same time needs its
own handle.
----
Steve Sapovits
Global Sports Interactive
Work Email: [EMAIL PROTECTED]
Home Email: [EMAIL PROTECTED]
Work Phone: 610-491-7087
Cell: 610-574-7706
Pager: 877-239-4003
> -----Original Message-----
> From: Tim Bunce [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, April 11, 2001 1:09 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: (Fwd) nesting queries?
>
> ----- Forwarded message from Scanman 20 <[EMAIL PROTECTED]> -----
>
> X-Originating-IP: [12.126.209.38]
> From: Scanman 20 <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: nesting queries?
> Date: Wed, 11 Apr 2001 09:50:28 -0400
> X-OriginalArrivalTime: 11 Apr 2001 13:50:28.0769 (UTC)
> FILETIME=[5E2F8110:01C0C28E]
>
> Hi Tim,
>
> I posed this question to alt.perl a while ago but never got an answer from
>
> anyone. Using Perl, Unix and MySQL, is it possible using DBI to nest
> database queries? I'm looking to do something like select all the records
> from one table, and then while I loop through all the records, run a
> second
> query inside the loop on another table in the same database. Something
> like
> this:
>
> $dbh = DBI->connect("dbi:mysql:database1", "user", "pwd") or choke("Can't
> connect to db: $DBI::errstr");
>
> $sth = $dbh->prepare("select * from Table1") or choke("Can't prepare
> statement: ",$dbh->errstr);
> $rv = $sth->execute;
>
> while (($some_stuff) = $sth->fetchrow_array) {
>
> $sth = $dbh->prepare("select * from Table2") or choke("Can't prepare
>
> statement: ",$dbh->errstr);
> $rv = $sth->execute;
> while (($some_more_stuff) = $sth->fetchrow_array) {
> print "blah blah blah\n";
> }#end inner while
>
> }#end outer while
>
> $dbh->disconnect;
>
>
> I've tried running this and it seems to run the outer loop ok, but after
> the
> first record of the inner loop gets returned, it stops and dies. If
> there's
> a better (or proper) way to do something like this I'd love to know how.
>
> Thanks,
>
> Jason
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> ----- End forwarded message -----