PHP PDO LIKE: escaping the% character when combined with a pattern
$percent = '%'; $st=$db->prepare("SELECT * FROM x WHERE y LIKE ?"); $st=$st->execute(array('%'.$percent.'%')); /*I want to get all records with the string % included like 5% etc.*/ The above example will not match correctly, instead matching all the records in table x. In order for this to work correctly, I obviously need to set $ percent = '\%'.
This is where I am left confused about the concept of ready-made applications. I thought that all the ready-made statements are that the value itself ($ percent) is simply interpreted as a string instead of a special wildcard. I would appreciate any feedback.
Thank you in advance
In the PDO tag (information) you will find the correct procedure for using wildcards in parameters. 
Then you can escape the % in the parameter.
$percent = '%\%%';//Escape % within % wildcards ....... $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); ......... $st=$db->prepare("SELECT * FROM x WHERE y LIKE ?"); $st=$st->execute(array($percent'));