Hi, You need to use two separate database and statement handles - you can only have one active query per handle.
eg. $dbh1 = DBI->connect(...); $dbh2 = DBI->connect(...); $sth1 = $dbh1->prepare( ... ); $sth1->execute(...); while ( $sth1->fetch() ) { $sth2 = $dbh2->prepare( ... ); $sth2->execute(...); while ( $sth2->fetch() ) { } } On Sat, 2002-08-31 at 20:23, Almar van Pel wrote: > Hello, > > I was trying to create a simple perl program, where my domains where listed > followed by there DNS records. > But It loops once, and then ends with error DBD::mysql::st fetch failed: > fetch() without execute() at test.cgi line 61. > > I thougt this was the easyest way to do so. But no.. Does anyone have any > experience with these kind of sub-statements? > > $dbh = DBI->connect("DBI:mysql:database=$db_database;host=$db_host", > $db_user, $db_pw) || > &db_error("Databaseverbinding niet gemaakt: $DBI::errstr"); > > $sql = "select domain from bind_dns_header"; > > $sth = $dbh->prepare($sql)|| &error("Kan het statement niet voorbereiden: > $dbh->errstr"); > $sth->execute || &error("Fout bij het communiceren met de database: > $DBI::errstr"); > $sth->bind_columns(\$domain); > > while ($sth->fetch()) { # line 61 > > print "$domain with the following records<br> \n"; > > $sql2 = "select dnsrecord_id from bind_dns_item where domain = > '$domain'"; > > > $sth = $dbh->prepare($sql2)|| &error("Kan het statement niet voorbereiden: > $dbh->errstr"); > $sth->execute || &error("Fout bij het communiceren met de database: > $DBI::errstr"); > $sth->bind_columns(\$dnsrecord_id); > while ($sth->fetch()) { > > print "Record: $dnsrecord_id \n"; > > } > > } > > $sth->finish(); > > Regards, > > Almar > > > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php