I spent my whole evening researching and trying to figure out what's wrong with my search query. I do some wildcard search using union queries and pagination.
$current_page = 0;
$search1 = $search;
$search2 = $search."%";
$search3 = "%".$search."%";
$pdo = DB::connection()->getPdo();
$stmt = $pdo->prepare('
SELECT id, desc FROM table WHERE desc LIKE :search1 LIMIT :skip, 15
UNION
SELECT id, desc FROM table WHERE desc LIKE :search2 LIMIT :skip, 15
UNION
SELECT id, desc FROM table WHERE desc LIKE :search3 LIMIT :skip, 15
');
$stmt->bindParam(':search1', $search1);
$stmt->bindParam(':search2', $search2);
$stmt->bindParam(':search3', $search3);
$stmt->bindParam(':skip', $current_page, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
The first query (without the unions) works fine, or if I remove the :skip parameter, it works fine as well.
Any ideas what's wrong?