MySQL LIKE + php sprintf

前端 未结 5 2261
陌清茗
陌清茗 2021-02-13 13:34
$test = sprintf(\"SELECT * FROM `table` WHERE `text` LIKE \'%%s%\'\", mysql_real_escape_string(\'test\'));

echo $test;

output:

SELECT          


        
5条回答
  •  孤独总比滥情好
    2021-02-13 14:02

    ... LIKE '%%%s%%'", mysql_real_escape_string('test'));
    

    To print the % character you need to escape it with itself. Therefore the first two %% will print the % character, while the third one is for the type specifier %s. You need a double %% at the end as well.

提交回复
热议问题