Hello!

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
>  
>

*look at the name of the statement handle above*

>       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");
>

Here is your problem! You overwrite the $sth which you want to use in 
the outer while. Use a different variable for the inner handle. In the 
inner while you already fetched all rows for sth returning to the next 
outer loop will fail.

>       $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();
>  
>


Greetings
 Ralf

-- 
Ralf Narozny

Besuchen Sie uns auf der DMS-Expo. SAP, Dokumenten-
management oder das komplette Office ins Portal einbinden?
Wir zeigen es Ihnen - vom 3. bis 5.9. auf der Messe Essen
Halle 3, Stand 3255

SPLENDID Internet GmbH & Co KG
Skandinaviendamm 212, 24109 Kiel, Germany
fon: +49 431 660 97 0, fax: +49 431 660 97 20
mailto:[EMAIL PROTECTED], http://www.splendid.de




---------------------------------------------------------------------
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

Reply via email to