A while back when working on a project I learned that when using the wild card: ‘%’ in SQL with a prepared statement you are going to get an error message. This is because the prepared statement class has an issue with a wild card surrounding wild cards. ‘%?%’.
Because of this a simple sql query such as this is going to have issues pulling data from the database.
1 | $sql = "SELECT * FROM tbl_comments WHERE comment LIKE %?% LIMIT 20"; |
Rather than attempt to get the above code to work you are going to need to take a separate approach and store the wild cards in with the search variable. This only takes one extra line of code and your search will be back up and running in no time at all.
1 2 | $comment = '%'.$comment.'%'; $sql = "SELECT * FROM tbl_comments WHERE comment LIKE ? LIMIT 20"; |