MySQL LIKE + php sprintf

前端 未结 5 2267
陌清茗
陌清茗 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 13:53

    You need to escape the percent signs with a percent sign %%.

    $test = sprintf("SELECT * FROM `table` WHERE `text` LIKE '%%%s%%'", mysql_real_escape_string('test'));
    
    echo $test;
    

提交回复
热议问题