If I run this simple query from the console by directly typing
SELECT COUNT(*) AS total FROM articles WHERE MATCH(title) AGAINST ('+php +mysql' IN BOOLEAN MODE)
I get plenty of results. Now I'm trying to prepare this statement in php.
$keywords = ['php', 'mysql'];
$against = '';
for($i = 0; $i < count($keywords); $i++){
$against .= '+? ';
}
$query = 'SELECT COUNT(*) AS total FROM articles WHERE MATCH(title) AGAINST ('.$against.' IN BOOLEAN MODE)';
//my query is now 'SELECT COUNT(*) AS total FROM articles WHERE MATCH(title) AGAINST (+? +? IN BOOLEAN MODE)'
$stmt = $pdo->prepare($query);
$stmt->execute($keywords);
This script only returns results if only 1 keyword is used. With 2 keywords, it returns no value and no error (but works in the console). So I suspect it's the way I prepare my statement with pdo. Any idea?