views:

28

answers:

1

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 BYtext_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 

Can anybody tell me what's wrong? i think it's the ->where bit, because when I remove it i get 10 rows.

+1  A: 

Edit: This works for me:

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

Let me know if that works.

no i didn't, but after doing it still get error `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 `
Moak
I tried it, and it generates a funtional query that way. The problem was the the WHERE clause should end up looking like this: WHERE s.name LIKE '%blah%'