Re: Query problem in Perl

2002-09-02 Thread Ralf Narozny

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




Re: Query problem in Perl

2002-09-02 Thread Martin Waite

On Mon, 2002-09-02 at 11:37, Harald Fuchs wrote:
> In article <1030961610.8175.5.camel@pascal>,
> Martin Waite <[EMAIL PROTECTED]> writes:
> 
> > 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() ) {
> > }
> > }
> 
> Nope.  You can have multiple active statement handles per database handle.
> 

Harald is correct (- thanks), but you still need a separate statement
handle for the query inside the loop:

$dbh1 = DBI->connect(...);

$sth1 = $dbh1->prepare( ... );
$sth1->execute(...);

while ( $sth1->fetch() ) {
$sth2 = $dbh1->prepare( ... );
$sth2->execute(...);
while ( $sth2->fetch() ) {
}
}



-
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




Re: Query problem in Perl

2002-09-02 Thread Martin Waite

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




Query problem in Perl

2002-08-31 Thread Almar van Pel

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




Query problem in Perl

2002-08-31 Thread Almar van Pel \(Koekjes.Net\)

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