DBI has a whole family of fetchrow() functions:
$sth = $dbh->prepare('SELECT catalog,name FROM ProductList')
|| die $dbh->errstr;
$sth->execute() || die $sth->errstr;
while (my $r = $sth->fetchrow_arrayref) {
my ($catalog,$name) = @$r;
print "catno => $catalog, name => $name\n";
}
$sth->finish;
|
$sth = $dbh->prepare('SELECT catalog,name FROM ProductList')
|| die $dbh->errstr;
$sth->execute() || die $sth->errstr;
while (my $r = $sth->fetchrow_hashref) {
print "catno => $r->{catalog}, name => $r->{name}\n";
}
$sth->finish;
|
Use "?" as a variable placeholder in SELECT or UPDATE statements. Avoids having to escape quotes, etc.
$sth = $dbh->prepare('SELECT name,description
FROM ProductList
WHERE catalog=?') || die $dbh->errstr;
$sth->execute('64-119293') || die $sth->errstr;
while (my $r = $sth->fetchrow_hashref) {
print "name => $r->{name}, description => $r->{description}\n";
}
$sth->finish;
|
$sth = $dbh->prepare('SELECT name,description
FROM ProductList
WHERE catalog=?') || die $dbh->errstr;
my ($name,$description);
$sth->bind_columns(undef,\($name,$description));
$sth->execute('64-119293') || die $sth->errstr;
while ($sth->fetch) {
print "name => $name, description => $description\n";
}
$sth->finish;
|
|
| Contents | Next |