CI活动记录API的$this->db->select部分做什么?


What does the $this->db->select portion of the CI Active Record API do?

我有这样的代码:

$this->db->select('title')->from('entries')->where('id', 1);
$query = $this->db->get();
echo $query->row('title');

回显条目表的标题,其中id等于1。

为什么没有'title in row函数就不能工作?

echo $query->row();

返回第一行?

为什么我必须有"标题"在两个地方($query->row$this->db->select),为了这个工作?这对我来说没有意义。

谁能解释这是如何工作的,据说提供从数据库中获取值的替代方法?

$this->db->select('title')->from('entries')->where('id', 1);

生成
SELECT title FROM entries WHERE id = 1

$query在数组中检索结果:

array( [0] => array( [title] => 'your title' ))

row('title')返回结果数组第一行的标题列。

您需要告诉它获取哪一列的原因是因为rowget可以与许多列一起使用。