正在为你努力加载中........

点滴记录 分享
14
2012-12
首页 >> CodeIgniter >> CodeIgniter 中的操作数据库函数

CodeIgniter 中的操作数据库函数

<?php
if (!defined('BASEPATH')) {
	exit('Access Denied');
}
class test_m extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->load->database();  //加载数据库
	}
	
	//插入数据
	function user_insert($array){
		$this->db->insert('user',$array);
	}
	//更新数据
	function user_update($uid,$array){
		return $this->db->update('user',$array,$uid);
	}
	//查询数据
	function user_select(){
		return $this->db->where_not_in('id',array(13,33))->select(array('username','id'))->get('user')->result();
	}
	//删除数据
	function user_del($where){
		return $this->db->delete('user',$where);
	}
	
	//inner join 查询
	function user_innerjoin(){
		//return $this->db->join('user','profile','INNER')->select(array('username','id','realname'))->get('user')->result();
	}
	
	function user_query(){
		$q =  $this->db->query("SELECT a.id,a.username,b.realname FROM user as a,profile as b WHERE a.id = b.uid");
		$dataarray = array();
		if($q->num_rows > 0){
			foreach($q->result() as $k=>$v){
				$dataarray[$k]['username'] = $v->id;
				$dataarray[$k]['uid'] = $v->username;
				$dataarray[$k]['realname'] = $v->realname;
				
				//$dataarray[] = $v;
			}
		}
		return $dataarray;
	}
	
}


作者:一根烟的寂寞 分类:CodeIgniter
浏览:94203 评论:0

发表评论: