Skip to content
Advertisement

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

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'];
}

Advertisement

Answer

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'];
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement