繁体   English   中英

Zend_Db的where子句无法按预期工作

[英]Where clause with Zend_Db not working as expected

我收到一个错误:
消息: 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 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 DESC LIMIT 10' at line 2 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_id DESC 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行。

编辑:这为我工作:

        ->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'));

让我知道是否可行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM