在Codeigniter中运行查询

时间:2013-08-29 08:06:52

标签: mysql codeigniter

此查询如何在Codeigniter中使用

`SELECT `messages`.`id`, left(`messages`.`message`, 150) 
     as 'message', `messages`.`message_group_id`, `messages`.`date_added` 
 FROM (`messages`) WHERE `message_group_id` = '".$messageGroupID."' 
 ORDER BY `messages`.`id` desc LIMIT 1`

3 个答案:

答案 0 :(得分:0)

$query = $this->db->query('YOUR QUERY HERE');

https://www.codeigniter.com/user_guide/database/queries.html

答案 1 :(得分:0)

尝试:

$this->db->select('messages.id, left(messages.message, 150) as message, messages.message_group_id, messages.date_added', false)->where('message_group_id', $messageGroupID)->order_by('messages.id', 'desc')->get('messages', 1);

答案 2 :(得分:0)

$ query = $ this-> db-> get('mytable',10,20);

//生成:SELECT * FROM mytable LIMIT 20,10(在MySQL中。其他数据库的语法略有不同)

有关详情,请参阅: LINK