热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CI框架中AR操作,ciar_PHP教程

CI框架中AR操作,ciar。CI框架中AR操作,ciarModel层中的部分代码1**2*CI中的AR操作3*@authorzhaoyingnan4**5publicfunctionmAR()6{7***************查询*****

CI 框架中 AR 操作,ciar


Model 层中的部分代码

 1     /**
 2      * CI 中的 AR 操作
 3      * @author    zhaoyingnan
 4      **/
 5     public function mAR()
 6     {
 7         /*************** 查询 *************/
 8         //select * from mp4ba limit 21,10;
 9         //$objResult    =    $this->db->get('mp4ba', 10, 21);
10         //echo $this->db->last_query();die;
11 
12 
13         //select * from mp4ba where id =32 limit 21,10;
14         //select * from mp4ba where id =32 and name = '刺客聂隐娘'limit 21,10;
15         //$objResult    =    $this->db->get_where('mp4ba', array('id'=>32), 10, 21);
16         //echo $this->db->last_query();die;
17         //$objResult    =    $this->db->get_where('mp4ba', array('id'=>32,'name'=>'刺客聂隐娘'), 10, 21);
18         //echo $this->db->last_query();die;
19 
20 
21         //select id,name,url from mp4ba where id =32;
22         //$objResult    =    $this->db->select('id,name,url')->get_where('mp4ba', array('id'=>32));
23         //echo $this->db->last_query();die;
24 
25         //select id,name,url from mp4ba where id =32 or id=39;
26         //$objResult    =    $this->db->select('id,name,url')->where(array('id'=>32))->or_where(array('id'=>39))->get('mp4ba');
27         //echo $this->db->last_query();die;
28         
29 
30         //select id,name,url from mp4ba where id in(33,44,55);
31         //select id,name,url from mp4ba where id in(33,44,55) or sort_id in (3,4);
32         //select id,name,url from mp4ba where id not in(33,44,55);
33         //$objResult    =    $this->db->select('id,name,url')->where_in('id', array(33,44,55))->get('mp4ba');
34         //$objResult    =    $this->db->select('id,name,url')->where_in('id', array(33,44,55))->or_where_in('sort_id', array(3,4))->get('mp4ba');
35         //$objResult    =    $this->db->select('id,name,url')->where_not_in('id', array(33,44,55))->get('mp4ba');
36         //echo $this->db->last_query();die;
37 
38         //select id,name,url from mp4ba join user on (mp4ba.uid=user.id) order by mp4ba.dateline desc;
39         //$objResult    =    $this->db->select('id,name,url')->from('mp4ba')->join('user', 'mp4ba.uid = user.id')->order_by('mp4ba.dateline', 'desc')->get();
40         //echo $this->last_query();die;
41 
42 
43         //select * from mp4ba where name like '%刺客%';
44         //select * from mp4ba where name not like '%刺客%';
45         //select * from mp4ba where name like '%刺客%' or url like 'eqfdf%';
46         //$objResult    =    $this->db->like('name', '刺客')->get('mp4ba');
47         //$objResult    =    $this->db->not_like('name', '刺客')->get('mp4ba');
48         //$objResult    =    $this->db->like('name', '刺客')->or_like('url', 'eqfdf', 'after')->get('mp4ba');
49         //echo $this->db->last_query();die;
50 
51 
52 
53         //select max(id) from mp4ba where name = '刺客聂隐娘';
54         //select min(id) from mp4ba where name = '刺客聂隐娘';
55         //$objResult    =    $this->db->select_max('id')->get_where('mp4ba', array('name'=>'刺客聂隐娘'));
56         //echo $this->db->last_query();die;
57         //$objResult    =    $this->db->select_min('id')->get_where('mp4ba', array('name'=>'刺客聂隐娘'));
58         //echo $this->db->last_query();die;
59 
60         //SELECT id,sort_id,menu,name FROM mp4ba WHERE id > 3 ORDER BY `dateline` desc LIMIT 10,100
61         //$objResult    =    $this->db->select('id,sort_id,menu,name')->from('mp4ba')->where('id >', 3)->order_by('dateline desc')->limit(100,10)->get();
62         //echo $this->db->last_query();
63         //return $objResult->result();
64 
65 
66         /*************** 插入 *************/
67         //生成一条基于你所提供的数据的SQL插入字符串并执行查询。你可以向函数传递 数组 或一个 对象。下面是一个使用数组的例子:
68         $arInsert    =    array(
69             'name'        =>    '小黄人',
70             'url'        =>    'www.test.com',
71             'sort_id'    =>    1,
72             'menu'        =>    '动画片'
73         );
74         //$this->db->insert('mp4ba', $arInsert);
75         //echo $this->db->insert_id();die;
76 
77 
78         /*************** 修改 *************/
79         $arData    =    array(
80             'name'        =>    '小黄人,好玩嘛',
81             'url'        =>    'www.test_xiaohuangren.com',
82             'sort_id'    =>    1,
83             'menu'        =>    '动画片'
84         );
85         //$this->db->update('mp4ba', $arData, array('id'=>3498));
86         //echo $this->db->affected_rows();    #受影响的行数
87         //echo '
';
88 //$objResult = $this->db->where(array('id'=>3498))->get('mp4ba'); 89 //formatOut($objResult->result());die; 90 91 /*************** 删除 *************/ 92 $this->db->delete('mp4ba', array('id'=>3498)); 93 echo $this->db->affected_rows(); #受影响的行数 94 }

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

1 php 2 class CI_DB_active_record 3 { 4 /** 5 * get 6 * @author zhaoyingnan 2015-10-14 12:50 7 * @param string $table 操作的表 8 * @param int $limit limit 值 9 * @param int $offset offset 值 10 * @return object 11 **/ 12 public function get($table = '', $limit = null, $offset = null) 13 {} 14 15 /** 16 * get_where 17 * @author zhaoyingnan 2015-10-14 12:58 18 * @param string $table 操作的表 19 * @param array $where where 子句 20 * @param int $limit limit 值 21 * @param int $offset offset 值 22 * @return object 23 **/ 24 public function get_where($table = '', $where = null, $limit = null, $offset = null) 25 {} 26 27 /** 28 * select 29 * @author zhaoyingnan 2015-10-14 13:13 30 * @param string $select 查询的字段,用逗号隔开 31 * @param boolean $escape 如果你把它设为FALSE, CodeIgniter 将不会使用反引号保护你的字段或者表名 。这在进行复合查询时很有用。 32 * @return object 33 **/ 34 public function select($select = '*', $escape = NULL) 35 {} 36 37 /** 38 * SELECT MAX(field) portion of a query* @description 39 * @author zhaoyingnan 2015-10-14 13:20 40 * @param string $select max(field)作用列 41 * @param string $alias 别名 42 * @return object 43 **/ 44 public function select_max($select = '', $alias = '') 45 {} 46 47 /** 48 * SELECT MIN(field) portion of a query 49 * @author zhaoyingnan 2015-10-14 13:20 50 * @param string $select min(field)作用列 51 * @param string $alias 别名 52 * @return object 53 **/ 54 public function select_min($select = '', $alias = '') 55 {} 56 57 /** 58 * SELECT AVG(field) portion of a query 59 * @author zhaoyingnan 2015-10-14 13:20 60 * @param string $select AVG(field)作用列 61 * @param string $alias 别名 62 * @return object 63 **/ 64 public function select_avg($select = '', $alias = '') 65 {} 66 67 /** 68 * SELECT SUM(field) portion of a query 69 * @author zhaoyingnan 2015-10-14 13:20 70 * @param string $select SUM(field)作用列 71 * @param string $alias 别名 72 * @return object 73 **/ 74 public function select_sum($select = '', $alias = '') 75 {} 76 77 78 /** 79 * @description 80 * @author zhaoyingnan 2015-10-14 13:26 81 * @param string $from 表名 82 * @return object 83 **/ 84 public function from($from) 85 {} 86 87 /** 88 * where 89 * @author zhaoyingnan 2015-10-14 13:31 90 * @param mix $key 传递数组的 key 值 91 * @param mix $value 传递数组的 key 对应的 value 值 92 * @return object 93 **/ 94 public function where($key, $value = NULL, $escape = TRUE) 95 { 96 //1,简单的 key/value 方法: 97 //$this->db->where('name', $name); 98 //生成: WHERE name = 'Joe' 99 100 //2.自定义 key/value 方法: 101 //$this->db->where('name !=', $name); 102 //$this->db->where('id <', $id); 103 //生成: WHERE name != 'Joe' AND id <45 104 105 //3.关联数组方法: 106 //$array = array('name' => $name, 'title' => $title, 'status' => $status); 107 //$this->db->where($array); 108 //生成: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' 109 //使用这个方法时你也可以包含运算符: 110 //$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date); 111 112 //4.自定义字符串: 113 //$where = "name='Joe' AND status='boss' OR status='active'"; 114 //$this->db->where($where); 115 return $this->_where($key, $value, 'AND ', $escape); 116 } 117 118 /** 119 * where 120 * @author zhaoyingnan 2015-10-14 13:31 121 * @param mix $key 传递数组的 key 值 122 * @param mix $value 传递数组的 key 对应的 value 值 123 * @return object 124 **/ 125 public function or_where($key, $value = NULL, $escape = TRUE) 126 { 127 //参考where 128 return $this->_where($key, $value, 'OR ', $escape); 129 } 130 131 132 /** 133 * where_in 134 * @author zhaoyingnan 2015-10-14 13:58 135 * @param string $key 要查询的列 136 * @param string $values 列的值得范围 137 * @return object 138 **/ 139 public function where_in($key = NULL, $values = NULL) 140 { 141 return $this->_where_in($key, $values); 142 } 143 144 /** 145 * or_where_in 146 * @author zhaoyingnan 2015-10-14 13:58 147 * @param string $key 要查询的列 148 * @param string $values 列的值得范围 149 * @return object 150 **/ 151 public function or_where_in($key = NULL, $values = NULL) 152 { 153 return $this->_where_in($key, $values, FALSE, 'OR '); 154 } 155 156 /** 157 * where_not_in 158 * @author zhaoyingnan 2015-10-14 13:58 159 * @param string $key 要查询的列 160 * @param string $values 列的值得范围 161 * @return object 162 **/ 163 public function where_not_in($key = NULL, $values = NULL) 164 { 165 return $this->_where_in($key, $values, TRUE); 166 } 167 168 /** 169 * or_where_not_in 170 * @author zhaoyingnan 2015-10-14 13:58 171 * @param string $key 要查询的列 172 * @param string $values 列的值得范围 173 * @return object 174 **/ 175 public function or_where_not_in($key = NULL, $values = NULL) 176 { 177 return $this->_where_in($key, $values, TRUE, 'OR '); 178 } 179 180 /** 181 * order by 182 * @author zhaoyingnan 2015-10-14 13:35 183 * @param string $orderby 被排序的列 184 * @param string $direction asc 或者 desc 185 * @return object 186 **/ 187 public function order_by($orderby, $direction = '') 188 {} 189 190 /** 191 * join 192 * @author zhaoyingnan 2015-10-14 14:07 193 * @param string $table 表名 194 * @param string $cond 条件 195 * @param string $type 指定 JOIN 的类型可选项包括:left, right, outer, inner, left outer, 以及 right outer 196 * @return 197 **/ 198 public function join($table, $cond, $type = '') 199 {} 200 201 /** 202 * like 203 * @author zhaoyingnan 2015-10-14 14:28 204 * @param stringi $field 错作的列 205 * @param mix $match 规则 206 * @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值) 207 * @return object 208 **/ 209 public function like($field, $match = '', $side = 'both') 210 { 211 return $this->_like($field, $match, 'AND ', $side); 212 } 213 214 /** 215 * not_like 216 * @author zhaoyingnan 2015-10-14 14:28 217 * @param stringi $field 错作的列 218 * @param mix $match 规则 219 * @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值) 220 * @return object 221 **/ 222 public function not_like($field, $match = '', $side = 'both') 223 { 224 return $this->_like($field, $match, 'AND ', $side, 'NOT'); 225 } 226 227 /** 228 * or_like 229 * @author zhaoyingnan 2015-10-14 14:28 230 * @param stringi $field 错作的列 231 * @param mix $match 规则 232 * @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值) 233 * @return object 234 **/ 235 public function or_like($field, $match = '', $side = 'both') 236 { 237 return $this->_like($field, $match, 'OR ', $side); 238 } 239 240 /** 241 * or_not_like 242 * @author zhaoyingnan 2015-10-14 14:28 243 * @param stringi $field 错作的列 244 * @param mix $match 规则 245 * @param mix $side 通配符(%)位置可用的选项是 'before', 'after' 以及 'both' (这是默认值) 246 * @return object 247 **/ 248 public function or_not_like($field, $match = '', $side = 'both') 249 { 250 return $this->_like($field, $match, 'OR ', $side, 'NOT'); 251 } 252 253 /** 254 * insert 单条插入 255 * @author zhaoyingnan 2015-10-14 14:52 256 * @param string $table 表名 257 * @param array $set 关联数组 258 * @return object 259 **/ 260 function insert($table = '', $set = NULL) 261 {} 262 263 /** 264 * insert 批量出入 265 * @author zhaoyingnan 2015-10-14 14:52 266 * @param string $table 表名 267 * @param array $set 关联数组 268 * @return object 269 **/ 270 public function insert_batch($table = '', $set = NULL) 271 {} 272 273 /** 274 * update 275 * @author zhaoyingnan 2015-10-14 15:02 276 * @param string $table 表名 277 * @param array $set 修改内容的关联数组 278 * @param mixed $where where条件 279 * @return object 280 **/ 281 public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) 282 {} 283 284 /** 285 * delete 286 * @author zhaoyingnan 2015-10-14 15:12 287 * @param mix $table 表名 288 * @param mixed $where where条件 289 * @return object 290 **/ 291 public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) 292 { 293 //第一个参数是表名,第二个参数是where子句。你可以不传递第二个参数,使用 where() 或者 or_where() 函数来替代它: 294 //$this->db->where('id', $id); 295 //$this->db->delete('mytable'); 296 297 298 //如果你想要从一个以上的表中删除数据,你可以将一个包含了多个表名的数组传递给delete()函数。 299 //$tables = array('table1', 'table2', 'table3'); 300 //$this->db->where('id', '5'); 301 //$this->db->delete($tables); 302 303 304 //如果你想要删除表中的全部数据,你可以使用 truncate() 函数,或者 empty_table() 函数。 305 } 306 307 /** 308 * limit 309 * @author zhaoyingnan 2015-10-14 14:34 310 * @param int $value 311 * @param int $offset 312 * @return object 313 **/ 314 public function limit($value, $offset = '') 315 {} 316 317 318 319 /** 320 * Where 321 * 322 * Called by where() or or_where() 323 * 324 * @param mixed 325 * @param mixed 326 * @param string 327 * @return object 328 **/ 329 protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) 330 {} 331 332 /** 333 * Like 334 * 335 * Called by like() or orlike() 336 * 337 * @param mixed 338 * @param mixed 339 * @param string 340 * @return object 341 **/ 342 protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') 343 { 344 if ( ! is_array($field)) 345 { 346 $field = array($field => $match); 347 } 348 349 foreach ($field as $k => $v) 350 { 351 $k = $this->_protect_identifiers($k); 352 353 $prefix = (count($this->ar_like) == 0) ? '' : $type; 354 355 $v = $this->escape_like_str($v); 356 357 if ($side == 'none') 358 { 359 $like_statement = $prefix." $k $not LIKE '{$v}'"; 360 } 361 elseif ($side == 'before') 362 { 363 $like_statement = $prefix." $k $not LIKE '%{$v}'"; 364 } 365 elseif ($side == 'after') 366 { 367 $like_statement = $prefix." $k $not LIKE '{$v}%'"; 368 } 369 else 370 { 371 $like_statement = $prefix." $k $not LIKE '%{$v}%'"; 372 } 373 374 // some platforms require an escape sequence definition for LIKE wildcards 375 if ($this->_like_escape_str != '') 376 { 377 $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); 378 } 379 380 $this->ar_like[] = $like_statement; 381 if ($this->ar_caching === TRUE) 382 { 383 $this->ar_cache_like[] = $like_statement; 384 $this->ar_cache_exists[] = 'like'; 385 } 386 387 } 388 return $this; 389 } 390 391 } View Code

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1060219.htmlTechArticleCI 框架中 AR 操作,ciar Model 层中的部分代码 1 /* * 2 * CI 中的 AR 操作 3 * @author zhaoyingnan 4 * */ 5 public function mAR() 6 { 7 /* ************** 查询 *****...


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • Monkey《大话移动——Android与iOS应用测试指南》的预购信息发布啦!
    Monkey《大话移动——Android与iOS应用测试指南》的预购信息已经发布,可以在京东和当当网进行预购。感谢几位大牛给出的书评,并呼吁大家的支持。明天京东的链接也将发布。 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了求解gcdexgcd斐蜀定理的迭代法和递归法,并解释了exgcd的概念和应用。exgcd是指对于不完全为0的非负整数a和b,gcd(a,b)表示a和b的最大公约数,必然存在整数对x和y,使得gcd(a,b)=ax+by。此外,本文还给出了相应的代码示例。 ... [详细]
  • 本文介绍了在微店中如何修改分销产品的价格以及设置价格的方法。客户在拍下商品后,在1小时内可以进行修改价格的操作,通过进入订单管理,点击未付款子项,可以找到订单信息并进行改价操作。修改价格后,买家会收到改价后的短信通知,在微店订单中进行付款即可。 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
author-avatar
lingdong369
一个脱离低级趣味的高级动物。
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有