Search two keys

(id)  title   contents
(1)   Asia     This is a continent
(2)   China    This country is big in population
(3)   France   This country is in Europe and Paris is its capital
(4)   Mongolia Mongol is country
(5)   Korea    Korea
(6)   Germany  Germany is in Europe and Berlin is its capital

I have a table like the above.

key1='a'; $key2='p'; $like1='%$key1%'; $like2='%key2%';
SELECT id, title, contents FROM myTable
WHERE contents like ? or contents like ? ORDER BY id
$searchQ=$dbc-> prepare ($sql);
$searchQ->execute([$like1, $like2]);

I am expecting 3 records called like the following but it actually calls NO records.

(2)   China    This country is big in population
(3)   France   This country is in Europe and Paris is its capital
(6)   Germany  Germany is in Europe and Berlin is its capital

What’s wrong in your view?

Well, for starters your query will return 5 records.
Secondly, this is the difference between a single quoted and double quoted string. Try making your like1 and like2 variables double quoted strings. Also add the missing $'s.

Thank you. doubleQuote and adding $, It was my careless, does work.

A post was merged into an existing topic: The rest part of SUBSTRING_IDEX