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

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; $sth->execute($word,$word,$word) || die "Error: " . $dbh->errstr; # do some stuff }



You are getting the error:

"Called with 3 bind variables when 0 are needed"

Because the DBI Doesn't think you have any bind variables to be filled because your ? ( Question Marks / Bind Variable Placeholders ) are within single quotes.

I believe that when using bind variables with the DBI you need to leave the ? ( question mark ) unquoted, or by itself.

Since you're doing a LIKE you can prepend, and append the percent signs to your variable $word.

Like this:
# Add percent sign for LIKE value in DB Search $word .= "\%$word\%";


Then modify your SQL Statement to look like this:
my $sth = $dbh->prepare( "SELECT * FROM my_table WHERE description LIKE ? OR shortdescription LIKE ? OR name LIKE ?" ) || die "Error: " . $dbh->errstr;


Definitely hope that helps! Good luck!