bind_columns ??

bind_columns ??

am 01.04.2005 06:25:42 von Michael Gale

Hello,

I was going over some tutorials online and am lost when the tutorial
starts the bind_column selection.

The part that I do not understand is:

my( $id, $name, $title, $phone );
$sth->bind_columns( undef, \$id, \$name, \$title, \$phone );

If I am not mistaken, the first statment creates the following
variables: $id, $name, $title, $phone.

The second statement then is what I do not get, why is the "undef" there
? and what does \$varname actually ?

I included the full example from the tutorial below.

Thanks.


--snip--
use strict;
use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:orcl',
'jeffrey',
'jeffspassword',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made:
$DBI::errstr";

my $sql = qq{ SELECT id, name, title, phone FROM employees };
my $sth = $dbh->prepare( $sql );
$sth->execute();

my( $id, $name, $title, $phone );
$sth->bind_columns( undef, \$id, \$name, \$title, \$phone );

while( $sth->fetch() ) {
print "$name, $title, $phone\n";
}

$sth->finish();
$dbh->disconnect();
--snip--

Michael

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: bind_columns ??

am 01.04.2005 06:48:30 von Rudy Lippan

On Thu, 31 Mar 2005, Michael Gale wrote:

> my( $id, $name, $title, $phone );
> $sth->bind_columns( undef, \$id, \$name, \$title, \$phone );
>
> If I am not mistaken, the first statment creates the following
> variables: $id, $name, $title, $phone.

Basically.

>
> The second statement then is what I do not get, why is the "undef" there
> ? and what does \$varname actually ?
>

IIRC, the undef should cause bind_columns to ignore the first column returned,
so in your example the first column of returned by the select statement is not
bound to anything, the second column is bound to $id &c. And \$varname creates
a reference to $varname. For more info on references perldoc 'perreftut'

-r


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org