CI中的AR(数据库增、删、改、查) (九)

CI中的AR(数据库增、删、改、查) (九)

1,首先配置文件

application/config/database.php

$query_builder = TRUE;

才能使用AR模型,如果是FALSE则不能使用AR模型

application/controllers/Welcome.php

//查询操作
public function index()
	{
		//$model = new Model('user');
		//$list = $model->select();
		$res = $this->db->get('user');
		foreach ($res->result() as $item){
			echo $item->name;
			echo "<br />";
		}
		
	}
//插入操作
public function index()
	{
		$data = array(
                        'name'=>'mary123',
                        'password'=>md5('mary'),
                );
        $bool = $this->db->insert('user',$data);
        自增id:$this->db->insert_id();
        受影响行数:$this->db->affected_rows();
		
	}
//更新操作
public function index()
	{
		$data = array(
				'email'=>'mary@gamil.com',
				'password'=>md5('12334545670')
		);
		$bool = $this->db->update('user',$data,array('id'=>3));
		var_dump($bool);
	}
//删除操作
public function index()
	{
		$bool = $this->db->delete('user',array('id'=>2));
		var_dump($bool);
	}


回复列表


回复操作