开发者社区> 问答> 正文

有没有一种方法可以使用ActiveRecord将参数传递给CodeIgniter中的查询而无需使用*

这是我想做的,但似乎不可能:(编辑:将单引号更改为双引号)

function get_archives($limit, $offset) { $query = $this->db->query(" SELECT archivalie.id, archivalie.signature, type_of_source.description AS type_of_source_description, media_type.description AS media_type_description, origin.description AS origin_description

    FROM    archivalie, 
            type_of_source, 
            media_type,
            origin

    WHERE   archivalie.type_of_source_id = type_of_source.id                                                        
    AND     type_of_source.media_type_id = media_type.id  
    AND     archivalie.origin_id = origin.id                                                                     

    ORDER BY    archivalie.id ASC
    LIMIT       $limit, $offset
"); 


// etc...

} 它给出此错误:(编辑:使用双引号并在URL中传递了偏移号的新错误消息)

ERROR: LIMIT #,# syntax is not supported HINT: Use separate LIMIT and OFFSET clauses. 仅当您使用ActiveRecord格式传递变量时,它才有效:

$this->db->select('archivalie.id, archivalie.signature, etc, etc'); // from, where, etc. $this->db->limit($limit, $offset);
$query = $this->db->get();

问题来源于stack overflow

展开
收起
保持可爱mmm 2019-11-18 16:05:21 435 0
1 条回答
写回答
取消 提交回答
  • $query = $this->db->query(' SELECT archivalie.id, archivalie.signature, type_of_source.description AS type_of_source_description, media_type.description AS media_type_description, origin.description AS origin_description FROM archivalie, type_of_source, media_type, origin WHERE archivalie.type_of_source_id = type_of_source.id
    AND type_of_source.media_type_id = media_type.id
    AND archivalie.origin_id = origin.id
    ORDER BY archivalie.id ASC LIMIT ? OFFSET ?',array($limit,$offset));

    2019-11-18 16:05:30
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
继承与功能组合 立即下载
JS 语言在引擎级别的执行过程 立即下载
用RxSwift写易维护易读的愉悦代码 立即下载