phppdo

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

Solution

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