Perl Database access

Hi,

I tried to run this code but it isnt giving me any output or errors.

My aim is to retrieve the row based on the flag name(this is the primary key).

flag_test is my table

This is how i ran it:

perl read_db.pl flag1

flag1 is the criteria in where clause

--------

this is my code:

#!/usr/bin/perl
use DBI;

sub read_db
{

$dbh = DBI -> connect('DBI:Oracle:mercury','student','learn') || die "unable to connect:$DBI::errstr";

my $dbh = DBI->connect();

my $sql = qq/select flag_name, f_name, l_name from flag_test where flag_name =?/;

my $sth = $dbh->prepare($sql);
$sth->execute();
my ($col1, $col2, $col3);

$sth->bind_col(1, \$col1);
$sth->bind_col(2, \$col2);
$sth->bind_col(3, \$col3);
while ($sth->fetch) {
print "$col1, $col2, $col3\n";
}

}

could somebody help me with this?

thanks,

mercury

The Execute() method allows you to specify placeholder params directly, that is how I do. I think there is no need to use bind_col(), but not sure about Oracle.

Then you can use fetchrow_hashref() to get back a hash reference which carries data from the row.

change

$sth->execute(); 

to

$sth->execute($ARGV[0]);  

you need to pass in the value for the parameter marker you set.