php - How do you do fuzzy searches using bound parameters in PDO? -


trying sort of thing...

where username '%$str%' 

...but using bound parameters prepared statements in pdo. e.g.:

$query = $db->prepare("select * comments comment :search"); $query->bindparam(':search', $str); $query->execute(); 

i've tried numerous permutations of single quotes , % signs , it's getting cross me.

i seem remember wrestling @ point before can't find references. know how (if?) can nicely in pdo named parameters?

ah. found comment on php.net reminded me of answer; need wildcard value before bindparam evaluated, , not worry quoting it. example works fine:

$str = "%$str%"; $query = $db->prepare("select * comments comment :search"); $query->bindparam(':search', $str); $query->execute(); 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -