How do I create a PDO parameterized query with a LIKE statement?

Andrew G. Johnson picture Andrew G. Johnson · Feb 24, 2009 · Viewed 96.8k times · Source

Here's my attempt at it:

$query = $database->prepare('SELECT * FROM table WHERE column LIKE "?%"');

$query->execute(array('value'));

while ($results = $query->fetch()) 
{
    echo $results['column'];
}

Answer

Andrew G. Johnson picture Andrew G. Johnson · Feb 24, 2009

Figured it out right after I posted:

$query = $database->prepare('SELECT * FROM table WHERE column LIKE ?');
$query->execute(array('value%'));

while ($results = $query->fetch())
{
    echo $results['column'];
}