KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to search the name field in my database using LIKE . If I craft the SQL 'by hand` like this: $query = "SELECT * \n" . "FROM `help_article` \n" . "WHERE `name` LIKE '%how%'\n" . ""; $sql = $db->prepare($query); $sql->setFetchMode(PDO::FETCH_ASSOC); $sql->execute(); Then it will return relevant results for 'how'. However, when I turn it into a prepared statement: $query = "SELECT * \n" . "FROM `help_article` \n" . "WHERE `name` LIKE '%:term%'\n" . ""; $sql->execute(array(":term" => $_GET["search"])); $sql->setFetchMode(PDO::FETCH_ASSOC); $sql->execute(); I am always getting zero results. What am I doing wrong? I am using prepared statements in other places in my code and they work fine.
Tags (comma-separated)
Save Edits
Cancel