“读取”查询
$this->db->select('url','name','clientid','people.surname AS client');
$this->db->where('clientid', '3');
$this->db->limit(5);
$this->db->from('sites');
$this->db->join('people', 'sites.clientid = people.id');
$this->db->orderby("name", "desc");
$query = $this->db->get();
显示查询结果
foreach ($query->result() as $row)
{
print $row->url;
print $row->name;
print $row->client;
}
if ($query->num_rows() > 0)
{
$row = $query->row_array();
print $row['url'];
print $row['name'];
print $row['client'];
}
“创建”和“更新”查询
$data = array(
'url' => 'www.mynewclient.com',
'name' => 'BigCo Inc',
'clientid' => '33',
'type' => 'dynamic'
);
$this->db->insert('sites', $data);
$this->db->set('url', 'www.mynewclinet.com');
$this->db->set('name', 'BigCo Inc');
$this->db->set('clientid', '33');
$this->db->set('type', 'dynamic');
$this->db->insert('sites');
Active Record 和传统 SQL 编程的结合
$this->db->query("SELECT id, name, url FROM sites WHERE 'type' = 'dynamic'");
$condition = "client ='3' AND (type ='dynamic' OR type='static')";
$this->db->where($condition);
共同学习,写下你的评论
评论加载中...
作者其他优质文章