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

后端 未结 7 1189
眼角桃花
眼角桃花 2020-11-22 04:47

Here\'s my attempt at it:

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

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

while ($r         


        
7条回答
  •  礼貌的吻别
    2020-11-22 05:17

    $query = $database->prepare('SELECT * FROM table WHERE column LIKE ?');
    $query->bindValue(1, "%$value%", PDO::PARAM_STR);
    $query->execute();
    
    if (!$query->rowCount() == 0) 
    {
        while ($results = $query->fetch()) 
        {
            echo $results['column'] . "
    \n"; } } else { echo 'Nothing found'; }

提交回复
热议问题