CI中的AR操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CI中的AR操作相关的知识,希望对你有一定的参考价值。
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 ‘<br/>‘;
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 }
转载:http://www.3fwork.com/b202/001766MYM021065/
以上是关于CI中的AR操作的主要内容,如果未能解决你的问题,请参考以下文章
spark关于join后有重复列的问题(org.apache.spark.sql.AnalysisException: Reference '*' is ambiguous)(代码片段