How to do LIKE search with PDO?

To do a LIKE search with PDO, I need to add the % parameter before passing it.

It works:

 $qry = ' SELECT product_id FROM cart_product WHERE product_manufacturer_num LIKE :search_string '; $sth = $this->pdo->prepare($qry); $sth->execute( array("search_string"=>'%'.$search_string.'%') ); 

For me, this is more like a hack, is there a more formal way to do this?

+5
php pdo
Oct 25 '10 at 13:50
source share
1 answer

It's good. I do not like it.

The problem occurs when you want to allow the letter character % or _ in the search bar without acting as a template.

+4
Oct 25 2018-10-10
source share



All Articles