Php 带PDO的LIKE关键字执行查询无法工作

Php 带PDO的LIKE关键字执行查询无法工作,php,sql,database,pdo,prepared-statement,Php,Sql,Database,Pdo,Prepared Statement,这是返回错误,我已经通过这个论坛上的其他几个答案尝试了一切,双引号,单引号。。但仍然很艰难。请有人解释一下 谢谢 $query_string = $this->conn->prepare('select category_id, thread_id, thread_title, thread_body from thread where thread_title LIKE :thread_title OR thread_body LIKE :thread_body'); $query

这是返回错误,我已经通过这个论坛上的其他几个答案尝试了一切,双引号,单引号。。但仍然很艰难。请有人解释一下

谢谢

$query_string = $this->conn->prepare('select category_id, thread_id, thread_title, thread_body from thread where thread_title LIKE :thread_title OR thread_body LIKE :thread_body');
$query_string->execute(array(':thread_title'=>"%$this->search_this%", ':thread_body'=>"%$this->search_this%"));
试试看

如果有任何问题,请告诉我。

类似SQL的查询就像

从thread中选择category_id、thread_id、thread_title、thread_body 其中线程标题类似于“线程标题”

或者你可以这样写 从thread中选择category_id、thread_id、thread_title、thread_body 其中线程标题如“线程标题%”

这意味着您的搜索字符串位于“”之间(单引号)

我不会像您那样使用pdo sql代码,我是这样编写的

$query\u string=$this->conn->prepare(“从线程中选择类别\u id、线程\u id、线程\u title、线程\u body,其中线程\u title类似于“%”,$this->search\u this。“%”或线程\u body类似于“%”,$this->search\u this。“%”);
$query_string->execute()

将参数绑定为stringsSo搜索此包含什么值?它与文本/字符串mashup查询一起工作吗?@mario真的没什么有趣的$this->search\u this=$\u GET[“search\u query”];我向上帝发誓,我会在几个小时前完成同样的事情/查询,工作得很好……也许输入中有空格或其他什么。尝试使用静态字符串进行测试。如果没有实际的数据库,恐怕这是不可回答的;因为代码看起来很好。让我尴尬的是,让我继续说这个。。我已经从文件中删除了db pass和user,所以我可以将其上载到github。。。忘记了将信息重新添加到文件中。。“没有实际的数据库可用”给了我一个线索。。。谢谢@mariothats这不是一个很好的答案或者我在找什么,先生。不管怎样,谢谢你。我在你的答案列表中没有看到过这样的答案。试试看。
$query_string = $this->conn->prepare('select category_id, thread_id, thread_title, thread_body from thread where thread_title LIKE :thread_title OR thread_body LIKE :thread_body');
$query_string->execute(array(':thread_title'=>'%'.$this->search_this.'%', ':thread_body'=>'%'.$this->search_this.'%'));