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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
