Re: impatient DBI query





-----Original Message-----
From: Beginner <dermot@xxxxxxxxxxxxxxxx>
Sent: Oct 31, 2007 9:20 PM
To: beginners@xxxxxxxx, beginners@xxxxxxxx
Subject: impatient DBI query

Hi,

I have ordered my Perl DBI book (is that a leopard?) but I am
impatient and want to know how I could do a select/like statement a
bit like this:

SELECT foo FROM bar WHERE foo like 'baz%'

the % being the wildcard operator.


try something like this:

my $dbh = DBI->connect(...);
my $str = 'select foo from bar where foo like ?';
my $sth = $dbh->prepare($str);
$sth->execute('baz%') or die $dbh->errstr;
my @results = $sth->fetchrow_array;
$sth->finish;

.