Model 层中的部分代码

     /**
* CI 中的 AR 操作
* @author zhaoyingnan
**/
public function mAR()
{
/*************** 查询 *************/
//select * from mp4ba limit 21,10;
//$objResult = $this->db->get('mp4ba', 10, 21);
//echo $this->db->last_query();die; //select * from mp4ba where id =32 limit 21,10;
//select * from mp4ba where id =32 and name = '刺客聂隐娘'limit 21,10;
//$objResult = $this->db->get_where('mp4ba', array('id'=>32), 10, 21);
//echo $this->db->last_query();die;
//$objResult = $this->db->get_where('mp4ba', array('id'=>32,'name'=>'刺客聂隐娘'), 10, 21);
//echo $this->db->last_query();die; //select id,name,url from mp4ba where id =32;
//$objResult = $this->db->select('id,name,url')->get_where('mp4ba', array('id'=>32));
//echo $this->db->last_query();die; //select id,name,url from mp4ba where id =32 or id=39;
//$objResult = $this->db->select('id,name,url')->where(array('id'=>32))->or_where(array('id'=>39))->get('mp4ba');
//echo $this->db->last_query();die; //select id,name,url from mp4ba where id in(33,44,55);
//select id,name,url from mp4ba where id in(33,44,55) or sort_id in (3,4);
//select id,name,url from mp4ba where id not in(33,44,55);
//$objResult = $this->db->select('id,name,url')->where_in('id', array(33,44,55))->get('mp4ba');
//$objResult = $this->db->select('id,name,url')->where_in('id', array(33,44,55))->or_where_in('sort_id', array(3,4))->get('mp4ba');
//$objResult = $this->db->select('id,name,url')->where_not_in('id', array(33,44,55))->get('mp4ba');
//echo $this->db->last_query();die; //select id,name,url from mp4ba join user on (mp4ba.uid=user.id) order by mp4ba.dateline desc;
//$objResult = $this->db->select('id,name,url')->from('mp4ba')->join('user', 'mp4ba.uid = user.id')->order_by('mp4ba.dateline', 'desc')->get();
//echo $this->last_query();die; //select * from mp4ba where name like '%刺客%';
//select * from mp4ba where name not like '%刺客%';
//select * from mp4ba where name like '%刺客%' or url like 'eqfdf%';
//$objResult = $this->db->like('name', '刺客')->get('mp4ba');
//$objResult = $this->db->not_like('name', '刺客')->get('mp4ba');
//$objResult = $this->db->like('name', '刺客')->or_like('url', 'eqfdf', 'after')->get('mp4ba');
//echo $this->db->last_query();die; //select max(id) from mp4ba where name = '刺客聂隐娘';
//select min(id) from mp4ba where name = '刺客聂隐娘';
//$objResult = $this->db->select_max('id')->get_where('mp4ba', array('name'=>'刺客聂隐娘'));
//echo $this->db->last_query();die;
//$objResult = $this->db->select_min('id')->get_where('mp4ba', array('name'=>'刺客聂隐娘'));
//echo $this->db->last_query();die; //SELECT id,sort_id,menu,name FROM mp4ba WHERE id > 3 ORDER BY `dateline` desc LIMIT 10,100
//$objResult = $this->db->select('id,sort_id,menu,name')->from('mp4ba')->where('id >', 3)->order_by('dateline desc')->limit(100,10)->get();
//echo $this->db->last_query();
//return $objResult->result(); /*************** 插入 *************/
//生成一条基于你所提供的数据的SQL插入字符串并执行查询。你可以向函数传递 数组 或一个 对象。下面是一个使用数组的例子:
$arInsert = array(
'name' => '小黄人',
'url' => 'www.test.com',
'sort_id' => 1,
'menu' => '动画片'
);
//$this->db->insert('mp4ba', $arInsert);
//echo $this->db->insert_id();die; /*************** 修改 *************/
$arData = array(
'name' => '小黄人,好玩嘛',
'url' => 'www.test_xiaohuangren.com',
'sort_id' => 1,
'menu' => '动画片'
);
//$this->db->update('mp4ba', $arData, array('id'=>3498));
//echo $this->db->affected_rows(); #受影响的行数
//echo '<br/>';
//$objResult = $this->db->where(array('id'=>3498))->get('mp4ba');
//formatOut($objResult->result());die; /*************** 删除 *************/
$this->db->delete('mp4ba', array('id'=>3498));
echo $this->db->affected_rows(); #受影响的行数
}

CI 中 DB_active_rec.php 该类中的部分方法的标注(会持续补充)

 <?php
class CI_DB_active_record
{
/**
* get
* @author zhaoyingnan 2015-10-14 12:50
* @param string $table 操作的表
* @param int $limit limit 值
* @param int $offset offset 值
* @return object
**/
public function get($table = '', $limit = null, $offset = null)
{} /**
* get_where
* @author zhaoyingnan 2015-10-14 12:58
* @param string $table 操作的表
* @param array $where where 子句
* @param int $limit limit 值
* @param int $offset offset 值
* @return object
**/
public function get_where($table = '', $where = null, $limit = null, $offset = null)
{} /**
* select
* @author zhaoyingnan 2015-10-14 13:13
* @param string $select 查询的字段,用逗号隔开
* @param boolean $escape 如果你把它设为FALSE, CodeIgniter 将不会使用反引号保护你的字段或者表名 。这在进行复合查询时很有用。
* @return object
**/
public function select($select = '*', $escape = NULL)
{} /**
* SELECT MAX(field) portion of a query* @description
* @author zhaoyingnan 2015-10-14 13:20
* @param string $select max(field)作用列
* @param string $alias 别名
* @return object
**/
public function select_max($select = '', $alias = '')
{} /**
* SELECT MIN(field) portion of a query
* @author zhaoyingnan 2015-10-14 13:20
* @param string $select min(field)作用列
* @param string $alias 别名
* @return object
**/
public function select_min($select = '', $alias = '')
{} /**
* SELECT AVG(field) portion of a query
* @author zhaoyingnan 2015-10-14 13:20
* @param string $select AVG(field)作用列
* @param string $alias 别名
* @return object
**/
public function select_avg($select = '', $alias = '')
{} /**
* SELECT SUM(field) portion of a query
* @author zhaoyingnan 2015-10-14 13:20
* @param string $select SUM(field)作用列
* @param string $alias 别名
* @return object
**/
public function select_sum($select = '', $alias = '')
{} /**
* @description
* @author zhaoyingnan 2015-10-14 13:26
* @param string $from 表名
* @return object
**/
public function from($from)
{} /**
* where
* @author zhaoyingnan 2015-10-14 13:31
* @param mix $key 传递数组的 key 值
* @param mix $value 传递数组的 key 对应的 value 值
* @return object
**/
public function where($key, $value = NULL, $escape = TRUE)
{
//1,简单的 key/value 方法:
//$this->db->where('name', $name);
//生成: WHERE name = 'Joe' //2.自定义 key/value 方法:
//$this->db->where('name !=', $name);
//$this->db->where('id <', $id);
//生成: WHERE name != 'Joe' AND id < 45 //3.关联数组方法:
//$array = array('name' => $name, 'title' => $title, 'status' => $status);
//$this->db->where($array);
//生成: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
//使用这个方法时你也可以包含运算符:
//$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date); //4.自定义字符串:
//$where = "name='Joe' AND status='boss' OR status='active'";
//$this->db->where($where);
return $this->_where($key, $value, 'AND ', $escape);
} /**
* where
* @author zhaoyingnan 2015-10-14 13:31
* @param mix $key 传递数组的 key 值
* @param mix $value 传递数组的 key 对应的 value 值
* @return object
**/
public function or_where($key, $value = NULL, $escape = TRUE)
{
//参考where
return $this->_where($key, $value, 'OR ', $escape);
} /**
* where_in
* @author zhaoyingnan 2015-10-14 13:58
* @param string $key 要查询的列
* @param string $values 列的值得范围
* @return object
**/
public function where_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values);
} /**
* or_where_in
* @author zhaoyingnan 2015-10-14 13:58
* @param string $key 要查询的列
* @param string $values 列的值得范围
* @return object
**/
public function or_where_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, FALSE, 'OR ');
} /**
* where_not_in
* @author zhaoyingnan 2015-10-14 13:58
* @param string $key 要查询的列
* @param string $values 列的值得范围
* @return object
**/
public function where_not_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, TRUE);
} /**
* or_where_not_in
* @author zhaoyingnan 2015-10-14 13:58
* @param string $key 要查询的列
* @param string $values 列的值得范围
* @return object
**/
public function or_where_not_in($key = NULL, $values = NULL)
{
return $this->_where_in($key, $values, TRUE, 'OR ');
} /**
* order by
* @author zhaoyingnan 2015-10-14 13:35
* @param string $orderby 被排序的列
* @param string $direction asc 或者 desc
* @return object
**/
public function order_by($orderby, $direction = '')
{} /**
* join
* @author zhaoyingnan 2015-10-14 14:07
* @param string $table 表名
* @param string $cond 条件
* @param string $type 指定 JOIN 的类型可选项包括:left, right, outer, inner, left outer, 以及 right outer
* @return
**/
public function join($table, $cond, $type = '')
{} /**
* like
* @author zhaoyingnan 2015-10-14 14:28
* @param stringi $field 错作的列
* @param mix $match 规则
* @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值)
* @return object
**/
public function like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'AND ', $side);
} /**
* not_like
* @author zhaoyingnan 2015-10-14 14:28
* @param stringi $field 错作的列
* @param mix $match 规则
* @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值)
* @return object
**/
public function not_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'AND ', $side, 'NOT');
} /**
* or_like
* @author zhaoyingnan 2015-10-14 14:28
* @param stringi $field 错作的列
* @param mix $match 规则
* @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值)
* @return object
**/
public function or_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'OR ', $side);
} /**
* or_not_like
* @author zhaoyingnan 2015-10-14 14:28
* @param stringi $field 错作的列
* @param mix $match 规则
* @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值)
* @return object
**/
public function or_not_like($field, $match = '', $side = 'both')
{
return $this->_like($field, $match, 'OR ', $side, 'NOT');
} /**
* insert 单条插入
* @author zhaoyingnan 2015-10-14 14:52
* @param string $table 表名
* @param array $set 关联数组
* @return object
**/
function insert($table = '', $set = NULL)
{} /**
* insert 批量出入
* @author zhaoyingnan 2015-10-14 14:52
* @param string $table 表名
* @param array $set 关联数组
* @return object
**/
public function insert_batch($table = '', $set = NULL)
{} /**
* update
* @author zhaoyingnan 2015-10-14 15:02
* @param string $table 表名
* @param array $set 修改内容的关联数组
* @param mixed $where where条件
* @return object
**/
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
{} /**
* delete
* @author zhaoyingnan 2015-10-14 15:12
* @param mix $table 表名
* @param mixed $where where条件
* @return object
**/
public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
{
//第一个参数是表名,第二个参数是where子句。你可以不传递第二个参数,使用 where() 或者 or_where() 函数来替代它:
//$this->db->where('id', $id);
//$this->db->delete('mytable'); //如果你想要从一个以上的表中删除数据,你可以将一个包含了多个表名的数组传递给delete()函数。
//$tables = array('table1', 'table2', 'table3');
//$this->db->where('id', '5');
//$this->db->delete($tables); //如果你想要删除表中的全部数据,你可以使用 truncate() 函数,或者 empty_table() 函数。
} /**
* limit
* @author zhaoyingnan 2015-10-14 14:34
* @param int $value
* @param int $offset
* @return object
**/
public function limit($value, $offset = '')
{} /**
* Where
*
* Called by where() or or_where()
*
* @param mixed
* @param mixed
* @param string
* @return object
**/
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{} /**
* Like
*
* Called by like() or orlike()
*
* @param mixed
* @param mixed
* @param string
* @return object
**/
protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
if ( ! is_array($field))
{
$field = array($field => $match);
} foreach ($field as $k => $v)
{
$k = $this->_protect_identifiers($k); $prefix = (count($this->ar_like) == 0) ? '' : $type; $v = $this->escape_like_str($v); if ($side == 'none')
{
$like_statement = $prefix." $k $not LIKE '{$v}'";
}
elseif ($side == 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
elseif ($side == 'after')
{
$like_statement = $prefix." $k $not LIKE '{$v}%'";
}
else
{
$like_statement = $prefix." $k $not LIKE '%{$v}%'";
} // some platforms require an escape sequence definition for LIKE wildcards
if ($this->_like_escape_str != '')
{
$like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr);
} $this->ar_like[] = $like_statement;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_like[] = $like_statement;
$this->ar_cache_exists[] = 'like';
} }
return $this;
} }

CI 框架中 AR 操作的更多相关文章

  1. CI 框架中的自定义路由规则

    在 CI 框架中,一个 URL 和它对应的控制器中的类以及类中的方法是一一对应的,如: www.test.com/user/info/zhaoyingnan 其中 user 对应的就是控制器中的 us ...

  2. php CI框架中URL特殊字符处理与SQL注入隐患

    php CI框架中URL特殊字符处理与SQL注入隐患 php CI框架中URL特殊字符有很多是不支持的,导致像c++,括号这些常用的分类,字符都无法正常显示很头痛,而在配置里增加单引号' 反斜杠\ 这 ...

  3. php json_encode在CI框架中的使用细节

    这个错误的造成原因是加载类类库,转换成json格式的时候不熟悉CI框架的规定导致的,CI框架中规定在将数据转换成json格式的时候需要将类库小写,当然了,调用的时候必须保证有这个类库,且可以在对应的文 ...

  4. CI框架中集成CKEditor编辑器的教程

    CKEditor是在很多开发过程中都会用到的一个富文本编辑器,那么如何在CI框架中使用它呢?这里介绍了在CI下使用CKEditor的方法,版本比较低,是在CI 1.7.3下使用fckeditor 2. ...

  5. CI 框架中的日志处理 以及 404异常处理

    最近在整理项目中的日志问题,查了一些关于 “CI 框架中的日志处理 以及 404异常处理” 的东西,顺便记录一下: 关于错误日志: 1. 在CI框架中的 system/core/CodeIgniter ...

  6. CI框架中的奇葩

    今天在win下开发,使用ci框架,本来是没有任何问题,然后转向了mac上开发,结果出现了个奇葩的问题,就是在ci框架中,控制器命名以"Admin_"为前缀的,在url中,控制器也必 ...

  7. 对CI框架中几个文件libraries

    对CI框架中几个文件libraries,helpers,hooks夹说明 来源:未知    时间:2014-10-20 11:37   阅读数:117   作者:xbdadmin [导读] 1.lib ...

  8. ci框架中model简单的mysql操作

    <?php class SingerModel extends CI_Model { function SingerModel() { //会将数据库对象赋值给CI_Controller的db属 ...

  9. 在CI框架中的配置整合amfphp

    之前做的项目用到CI框架和amfphp的整合,主要用于php与flex的交互,在此做一下记录: 一. 安装CI框架: 1.  搭建PHP运行环境,本人在WIN7下用WAMP作测试,安装目录:d:/wa ...

随机推荐

  1. 交通银行 Java Socket 服务启动 管理 WINDOWS 版

    按照交通银行提供的无界面启动方法试验了很多次,都没有成功,所以自己动手用C# 知识写了一个. 小工具可以判断 交通银行 JAVA SOCKET 服务是否启动,并可以启动/关闭服务 主要代码如下: 判断 ...

  2. 创建Google网站地图Sitemap.xml

    Sitemap.xml是google搞出来的,也就是网站地图,不过这个网站地图是用xml写的,而且要按google的标准来写,并且要将写出来的这个文件sitemap.xml上传到自己的服务器空间中去. ...

  3. WdatePicker.js的使用方法

    WdatePicker.js的使用方法 摘自:http://www.cnblogs.com/wuchao/archive/2012/07/19/2599209.html 4. 日期范围限制 静态限制  ...

  4. HDU 1069---背包---Monkey and Banana

    HDU 1069 Description A group of researchers are designing an experiment to test the IQ of a monkey. ...

  5. SDK Build Tools revision (19.0.3) is too low for project Min

    SDK Build Tools revision (19.0.3) is too low for project Min(转)       如果你正在使用Android Studio工具进行开发,且将 ...

  6. TeamCity配置笔记

    1.编译sln 2.发布网站 3.重复代码检测 4.代码分析 5.单元测试&覆盖率测试 查看代码覆盖率 7.代码签入时自动触发编译 8.通知 1.在teamcity安装目录中找到TrayNot ...

  7. Activity与Fragment的生命周期

    今天看到一张图,详细描述了Activity和Fragment的生命周期,好资源共享咯!

  8. GCD中的dispatch_semaphore的语法与作用

    (一)引入问题 当并行执行的处理更新数据时,会产生数据不一致的情况,有时应用程序还会异常结束,虽然使用Serial Dipatch queue和dispatch_barrier_async函数可避免这 ...

  9. HTML列表元素

    HTML定义了3类列表: 1.有序列表(通常用数字编号) 2.无序列表(通常前面加原点) 3.自定义列表(列表项目,带有集成的定义) 有序列表和无序列表均为列表中的每一项使用列表项元素(<li& ...

  10. GCD编程 之 略微提高篇

    额外任务:学习YouXianMing封装好的GCD源码   1.GCD串行队列与并发队列   串行队列一次只执行一个线程,按照添加到队列的顺序依次执行 并发队列一次可以执行多个线程,线程的执行没有先后 ...