neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
I'm having trouble using bind_param in DBI with the Postgresql driver. I'm using the results of one query as bind params for a second query. The loop does print out $bind_class, but bind_param statement seems to do nothing. Only the bind_param outside of the loop results in something being returned. What have I done wrong?
my $sth = $dbh->prepare( $query ) || die "Could not prepare" ; foreach my $row ( @$class_arrayref ) { ( $bind_class ) = @$row; print "class = ".$bind_class."\n"; #debugging, works! $sth->bind_param( 1, $bind_class ); # does not work } my $class = 'debian%'; $sth->bind_param( 1, $class ); # works! $sth->execute; my $rows = $sth->fetchall_arrayref();
I did not understand how bind_param works. I understood that this would execute the same statement multiple times with a different where clause and I could combine the results. I now see that was silly and inefficient of me. Sorry for the noise. Feel free to reap this node.
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: bind_param in DBI not working
by hippo (Archbishop) on Mar 15, 2014 at 19:28 UTC | |
|
Re: bind_param in DBI not working
by Erez (Priest) on Mar 16, 2014 at 16:37 UTC |