Can you try this ? It may work. ( I haven't tested it ).
$sth->bind_columns(eval($BCS));

-----Original Message-----
From: Ronald J Kimball [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 20, 2002 9:28 AM
To: Troy Sniff
Cc: [EMAIL PROTECTED]
Subject: Re: bind_columns question


On Tue, Mar 19, 2002 at 09:21:26PM -0700, Troy Sniff wrote:
> I am trying to perform some column binding by reading the column names
> of a table and binding to variables that coincide with those column
> names.
> 
> Example:
> 
> -----------
> 
> $sth = $dbh->prepare( "SELECT * FROM Table" );
> $sth->execute();
> my $count = 1;
> foreach my $bcs (@{$sth->{NAME}})
>  {
>       $sth->bind_col( $count, \$$bcs);
>       $count++;
>  }
> 
> -----------
> 
> The above works fine, however the following fails.
> 
> -----------
> 
> $sth = $dbh->prepare( "SELECT * FROM Table" );
> $sth->execute();
> my $BCS = '\$'.join(',\$',@{$sth->{NAME}});
> $sth->bind_columns($BCS);
> 
> -----------
> 
> Can bind_columns be used in this way?

What is the difference between these two snippets of Perl code?

$x = 1;
$y = 2;
$z = $x + $y;
print "$z\n";

$x = 1;
$y = 2;
$z = '$' . join ' + $', 'x', 'y';
print "$z\n";


To answer your question, although bind_columns could be used in that way,
what you're trying to do is use symbolic references.  That's generally a
bad idea.  (What would happen if one of the columns were named 'sth'?)  Use
a hash instead:

my %values;
$sth->bind_columns(@values{@{$sth->{NAME}}});

or just call fetchrow_hashref().

Ronald
This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and delete
this e-mail from your system. 
E-mail transmission cannot be guaranteed to be secure or error-free. The
sender therefore does not accept liability for any errors or omissions in
the contents of this message that arise as a result of e-mail transmission.
This message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments. 
 All e-mails at Neuberger Berman are, in accordance with Firm policy, to be
used for Neuberger Berman business purposes only. E-mails sent from or to
the Firm are subject to being reviewed by the Firm in accordance with the
Firm's procedure for the review of correspondence.

Reply via email to