vergil 发表于 2012-2-10 11:48:20

CI怎么操作多个数据表前缀?

我的数据库里有多种数据表前缀,怎么用CI内置的数据库方法去查询呢?
CI会自动给加上前缀

vergil 发表于 2012-2-10 11:49:27

再问多一个问题

联表查询怎么用AS取别名?

Hex 发表于 2012-2-10 12:00:27

CI 数据库前缀只支持一个,如果你有多个前缀,请自行添加前缀,而不要用 CI 的。
as 都是直接在字段后面 as 就可以了。

vergil 发表于 2012-2-10 13:00:04

就是说不要在database配置文件写前缀?
然后写表明的时候写全名?

vergil 发表于 2012-2-10 13:02:59

比如说这段代码

$this->db->select('*,
                '.$this->getTablename().'.id as id,
                '.$this->getTablename().'.name as name,
                '.$this->getTablename().'.ctime as ctime,
                '.$this->getTablename().'.mtime as mtime,
                category.id as catid,
                category.name as catname,
                category.ctime as catctime,
                category.mtime as catmtime');

$this->db->from($this->getTablename());

if( ! empty($where) && is_array($where))
        $this->db->where($where);

$this->db->order_by($this->getTablename().'.ctime', 'DESC');
$this->db->join('category', $this->getTablename().'.category_id = category.id', 'left');
$this->db->limit((int)$limit, (int)$offset);
$products = $this->db->get()->result_array();



怎么给数据表用as?

Hex 发表于 2012-2-10 13:04:17

vergil 发表于 2012-2-10 13:00 static/image/common/back.gif
就是说不要在database配置文件写前缀?
然后写表明的时候写全名?

是的,自己写表名的时候写全名。

Hex 发表于 2012-2-10 13:05:22

vergil 发表于 2012-2-10 13:02 static/image/common/back.gif
比如说这段代码




你这么复杂的 SQL 建议用 query(),AR 不是支持所有 SQL 语句的。

vergil 发表于 2012-2-10 13:56:42

谢谢回答
页: [1]
查看完整版本: CI怎么操作多个数据表前缀?