<p>Trying to do this sort of thing...</p>

<pre><code>WHERE username LIKE '%$str%'
</code></pre>

<p>...but using bound parameters to prepared statements in PDO. e.g.:</p>

<pre><code>$query = $db-&gt;prepare("select * from comments where comment like :search");
$query-&gt;bindParam(':search', $str);
$query-&gt;execute();
</code></pre>

<p>I've tried numerous permutations of single quotes and % signs and it's just getting cross with me.</p>

<p>I seem to remember wrestling with this at some point before but I can't find any references. Does anyone know how (if?) you can do this nicely in PDO with named parameters?</p>

Ah. Found a comment on php.net that reminded me of the answer; you need to wildcard your value before the bindParam is evaluated, and not worry about quoting it. So for example this works fine:
```
```
$str = "%$str%";
$query = $db->prepare("select * from comments where comment like :search");
$query->bindParam(':search', $str);
$query->execute();
```
```