0

hi i'm getting an invalid parameter number when executing php PDO select statement with JOIN and LIKE below is my code

try {
$search = ('SELECT torrents.ID,torrents.ImgUrl,torrents.Title,songs.Song from torrents INNER JOIN songs ON torrents.ID = songs.ID where torrents.Title Like :search_query or songs.Song Like :search_query');
$search = $a->prepare($search);
$search_query = "%$search_query%";
$search->execute(array(':search_query' => $search_query));
$search_query = $search->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
  echo $e->getMessage();
}

I have tried using placeholders torrents.Title Like ? OR songs.Song Like ?and execute it with $search->execute($search_query); Still i'm getting an error.

Junius L
  • 15,881
  • 6
  • 52
  • 96
  • With `PDO_MySQL` you cannot reuse a :named parameter. You need to bind it twice; with different names. Enumerated placeholders `?` might be advantageous here. – mario Jul 20 '14 at 22:27
  • @mario how is this question a duplicate? just because they have the same heading? – Junius L Jul 20 '14 at 22:35
  • How isn't it? Elaborate if your problem differs. What part of it is not applicable? Question uniqueness isn't about different variable names. – mario Jul 20 '14 at 22:39
  • @mario the other one uses insert and mine uses multiple mysql statements. – Junius L Jul 20 '14 at 22:41
  • You have just one query. This PDO constraint (depending on driver, PDO version, and EMULATE_PREPARES btw) isn't going to change depending on the statement clause. Also please use the [edit link](http://stackoverflow.com/posts/24855480/edit) instead of comments to add distinct infos on what you've tried or prior research. – mario Jul 20 '14 at 22:45
  • Just needs `$search->execute(array($search_query, $search_query));` for two `?` placeholders. – mario Jul 20 '14 at 23:32

0 Answers0