十九章 CI笔记 简化数据库开发

释放双眼,带上耳机,听听看~!

“读取”查询
$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);

【转自慕课】https://www.imooc.com

PHP

如何理解php中命名空间概念

2022-3-3 2:11:50

PHP

安装php编译报错解决办法

2022-3-3 2:13:53

搜索