好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

CodeIgniter数据库的使用

载入database,

 

$this->load->database();

也可在config文件夹下的autoload.php文件中修改:

$autoload['libraries'] =array('database');

这样,就可以使用了。

查询单条数据:

 

$this->db->select('title, content, date');

$query=$this->db->get_where('test',array('id'=>$id));

//$this->db->where('id', $id); 

//$query = $this->db->get('test');

return$query->row_array();

查询多条数据:

 

$this->db->select('title, content, date');

$query=$this->db->get('test');

//$this->db->from('test');

//$query = $this->db->get();

$this->db->order_by("title","desc"); 

return$query->result_array();

获取数据库中的记录总数:

 

$this->db->count_all(‘test');

$this->db->where('aid',$aid);

return$this->db->count_all_results('test');

 

查看更多关于CodeIgniter数据库的使用的详细内容...

  阅读:41次