When I AND together two LIKEs in a SQL query, it works fine if I execute it straight on the server. Things get strange when I use PDO to bind variables.
On the server the following works as expected
SELECT * FROM CarParkMain WHERE Make LIKE '%b%' AND Model LIKE '%02 (e10)%'
The following statements bring expected results in my PHP
SELECT * FROM CarParkMain WHERE Model LIKE :b
SELECT * FROM CarParkMain WHERE Make LIKE :a
SELECT * FROM CarParkMain WHERE Make LIKE '%b%' AND Model LIKE '%02 (e10)%'
The following statement does not work (zero results)
SELECT * FROM CarParkMain WHERE Make LIKE :a AND Model LIKE :b
This statement returns the results of the Make LIKE only, suggesting the Model LIKE returns nothing (contradicting with statement above where the Model LIKE is alone, that brings results)
SELECT * FROM CarParkMain WHERE Make LIKE :a OR Model LIKE :b
I can create the issue with the code below. Any ideas? Am I missing something stupid?
$prepared = $pdo->prepare("SELECT * FROM CarParkMain WHERE Make LIKE :a AND Model LIKE :b");
$filter = "%b%";
$prepared->bindParam(":a", $filter);
$filter = "%02 (e10)%";
$prepared->bindParam(":b", $filter);
$prepared->execute();
$rows = $prepared->fetchAll();