Zend_Db 的 Where 子句未按预期工作
我收到错误:
消息: SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '%'Chinese'% 附近使用的正确语法。 ORDER BY
text_idDESC LIMIT 10' at line 2
由这行代码引起代码
$select = $this->_db->select('')
->from(array('t'=>'as_text'))
->where('`s`.`name` LIKE %?%',$search) //this is causing error
->limit((int)$limit)
->order('text_id DESC')
->join(array('s'=>'as_source'),'t.source_id = s.source_id',array('s.name as source'));
我的目标是这个sql:
SELECT `t` . * , `s`.`name` AS `source`
FROM `as_text` AS `t`
INNER JOIN `as_source` AS `s` ON t.source_id = s.source_id
WHERE `s`.`name` LIKE '%Chinese%'
ORDER BY `text_id` DESC
LIMIT 10
我认为它是 ->where 位,因为当我删除它时,我得到 10 行。
I am getting an error:
Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'Chinese'%) ORDER BY
text_idDESC LIMIT 10' at line 2
caused by this line of code
$select = $this->_db->select('')
->from(array('t'=>'as_text'))
->where('`s`.`name` LIKE %?%',$search) //this is causing error
->limit((int)$limit)
->order('text_id DESC')
->join(array('s'=>'as_source'),'t.source_id = s.source_id',array('s.name as source'));
My target is this sql:
SELECT `t` . * , `s`.`name` AS `source`
FROM `as_text` AS `t`
INNER JOIN `as_source` AS `s` ON t.source_id = s.source_id
WHERE `s`.`name` LIKE '%Chinese%'
ORDER BY `text_id` DESC
LIMIT 10
i think it's the ->where bit, because when I remove it i get 10 rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
这对我有用:
让我知道这是否有效。
Edit:
This works for me:
Let me know if that works.