[英]PHP-Mysql error with %
I wrote a very simple mysql line for my very simple search bar that searches keywords, but I ran through an error. 我为非常简单的搜索栏写了一个非常简单的mysql行,用于搜索关键字,但遇到了错误。 (I have a feeling it's because of the length of the search)
(我感觉是由于搜索时间长)
$query = "SELECT * FROM entries WHERE name='%".$search."%' ";
works, but 可行,但是
$query = "SELECT * FROM entries WHERE desc='%".$search."%' ";
doesn't. 没有。
In the database, name has around 20 characters, and desc has around 700. I checked spelling and everything, it just outputs an error. 在数据库中,名称大约有20个字符,而desc大约有700个字符。我检查了拼写和所有内容,它只会输出错误。
Does it not work because it has too many characters to scan through? 它扫描的字符太多,无法正常工作吗?
Thanks a lot (in advance)! 非常感谢(提前)!
desc
是mysql的关键字,需要用引号引起来,并且应使用LIKE
而不是=
,并确保$search
已被转义。
$query = "SELECT * FROM entries WHERE `desc` LIKE '%".$search."%' ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.