gpt4 book ai didi

php - MySQL LIKE + php sprintf

转载 作者:IT老高 更新时间:2023-10-29 00:08:59 25 4
gpt4 key购买 nike

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

echo $test;

输出:

SELECT * FROM `table` WHERE `text` LIKE '%s

但它应该输出:

SELECT * FROM `table` WHERE `text` LIKE '%test%'

最佳答案

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

要打印 % 字符,您需要将其自身转义。因此前两个 %% 将打印 % 字符,而第三个用于类型说明符 %s。最后你还需要一个双 %%

关于php - MySQL LIKE + php sprintf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3863199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com