I think this question is been asked for php and now I am asking it for perl. I have 2 arrays. I am using it to query my database. Now it happens that the terms are not just a word and so it may have spaces in it.
I declared 2 variables, say $foo and $bar. I have 2 for loops that goes and combine each of terms in file 1 to each of terms in file 2 and queries the database. Each time each term goes into the variables. The database is text-indexed. I am using DBI module. My query is something like this:
my $query_handle = $connect->prepare("SELECT value FROM value_table WHERE
MATCH(column_text_indexed) AGAINST ('+"$foo" +"$bar"' in boolean mode)") || die
"Prepare failed:$DBI::errstr\n";
It gives the following error:
Scalar found where operator expected at program.pl line 32, near ""SELECT value FROM value_table
WHERE MATCH(column_text_indexed) AGAINST ('+"$foo"
(Missing operator before $foo?)
String found where operator expected at program.pl line 32, near "$foo" +""
(Missing operator before " +"?)
Scalar found where operator expected at program.pl line 32, near "" +"$bar"
(Missing operator before $bar?)
String found where operator expected at program.pl line 32, near "$bar"' in boolean mode)""
(Missing operator before "' in boolean mode)"?)
syntax error at program.pl line 32, near ""SELECT value FROM value_table WHERE
MATCH(column_text_indexed) against ('+"$foo"
Execution of program.pl aborted due to compilation errors.
Also, my other concern: is it right to use quotes around the terms when the terms are like “81-alpha-hydroxylase deficiency” or “26-deoxysteroid activity stable”? According to the http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html it says to use quotes if one is searching for exact terms and I want the exact terms to be searched. When I use () I get results but then I think it considers the whole word separated by spaces as different words and gives me result for any one of it.
Any help is greatly appreciated.
Thank you.
Say you want to create the string
(Yes, I’m ignoring interpolation for now.)
You can’t just place the whole thing in double quotes because the string literal will end at the first double quote encountered. You also need to escape the existing double quotes (and any other characters that are special in double-quoted strings).
Alternatively, you can use a different delimiter like
or
Now let’s interpolate the values we actually want.
All together:
Note the use of a placeholder! Always use placeholders. (Search for that word in the DBI documentation if you don’t know this already.) If
$fooor$barcontains a double-quote or other weird characters, your data won’t be accidentally interpreted as code.