LoginSignup
0
0

More than 3 years have passed since last update.

PHPでlike検索かける方法

Posted at

likeを使った検索方法

誤った方法

   $lists = $db->prepare('SELECT * FROM example WHERE like "%?%" ;');
    $lists -> execute(array($_SESSION['key']));
}

これだと、%も?もエスケープされていないので、期待した値が得られない

正しい方法

      $lists = $db->prepare('SELECT * FROM example WHERE  like ? ;');
    $lists -> execute(array('%'.$_SESSION['key'].'%'));
}

つまり、「%」ごと挿入すると考えることが重要であると分かった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0