【发布时间】:2013-08-06 13:32:18
【问题描述】:
基本上,我有这样的编码约定,即任何作为 ID 的主键,我都会将列名称为“id”。所以我的问题来了。我正在加入两个表,我得到的是第二个表的 ID,而不是第一个表。我知道如果我使用 select "artists.id, ..." 它会起作用,但我想知道是否有使用 "select *" 的修复,这对于未来的扩展会更好(新的列将会出现......) .
这是我的模型:
$this->db->select('*');
$this->db->from('artists');
$this->db->join('categories', 'artists.category_id = categories.id');
$this->db->where('id', $id);
$this->db->limit(1);
使用 Print_R,我可以看到我正在获取所有列(但只有 1 个 id,它来自类别表而不是艺术家表),没有任何表前缀。
【问题讨论】:
-
没有。避免使用“SELECT *”。
标签: php mysql codeigniter select join