in reply to DBI - I can't use bind variables with "like"?

This can be changed as :
foreach my $word (@words) { my $sth = $dbh->prepare( "SELECT * FROM my_table WHERE description LIKE '?' OR shortdescription LIKE '?' OR name LIKE '?'" ) || die "Error: " . $dbh->errstr; #append and prepend percentage signs $word ="%".$word."%" ; $sth->execute($word,$word,$word) || die "Error: " . $dbh->errstr; # do some stuff }
Append and prepend % sign to each element.
I believe this should work. (Code is untested!!)
Thanks..

Replies are listed 'Best First'.
Re^2: DBI - I can't use bind variables with "like"?
by clinton (Priest) on Jun 30, 2006 at 08:43 UTC

    Your code wouldn't work because you have quoted the placeholders : LIKE '?'

    Instead you should do as recommended in the reply by lestrrat and leave them unquoted : LIKE ?