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

后端 未结 7 1208
眼角桃花
眼角桃花 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:16

    PDO escapes "%" (May lead to sql injection): The use of the previous code will give the desire results when looking to match partial strings BUT if a visitor types the character "%" you will still get results even if you don't have anything stored in the data base (it may lead sql injections)

    I've tried a lot of variation all with the same result PDO is escaping "%" leading unwanted/unexcited search results.

    I though it was worth sharing if anyone has found a word around it please share it

提交回复
热议问题