This is my code:
$sch = '%test%';
$select_search_query = "(
SELECT
GROUP_CONCAT(name, ' ', surname) AS result
FROM users
WHERE
(
email LIKE :sch OR
name LIKE :sch OR
surname LIKE :sch
)
AND
id_p = :ff_z
)";
$prep_search_query = $connection->prepare($select_search_query);
$prep_search_query->bindParam(":sch", $sch);
$prep_search_query->bindParam(":ff_z", $id_p, PDO::PARAM_INT);
$prep_search_query->execute();
$array_search = $prep_search_query->fetchAll(PDO::FETCH_ASSOC);
print_r($array_search);
// The output is empty
After spending a pair of hours, searching for the possible mistakes, I finally decided to come out here, because I don't know why this is happening...
I'm programming a search page and it must works using PDO. The above code, doesn't works, however, the following one does:
//$sch = '%test%';
$select_search_query = "(
SELECT
GROUP_CONCAT(name, ' ', surname) AS result
FROM users
WHERE
(
email LIKE '%test%' OR
name LIKE '%test%' OR
surname LIKE '%test%'
)
AND
id_p = 1
)";
$prep_search_query = $connection->prepare($select_search_query);
$prep_search_query->execute();
$array_search = $prep_search_query->fetchAll(PDO::FETCH_ASSOC);
print_r($array_search);
// The output is a very long array
It seems the problem is located in the LIKE, but I don't find the solution, I've tested many things and got no results. Thanks!