Advertisement
MSupian

Contoh Penggunaan Model Query CodeIgniter ala Supian M

Oct 25th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. Contoh penggunaan Model Query CodeIgniter ala Supian, M :D
  2.  
  3. Script : http://pastebin.com/A55pHBZh
  4.  
  5. #======================================================
  6. $this->query->QueryData('name, email', 'users');
  7. #======================================================
  8. #                       SAMA DENGAN
  9. #======================================================
  10. $this->db->select('name, email');
  11. $this->db->get('users');
  12. #======================================================
  13.  
  14.  
  15. #======================================================
  16. $where = array('where' => array('username' => $this->session->userdata('username')),'or_where' => false);
  17. $this->query->QueryData('name, email', 'users', $where);
  18. #======================================================
  19. #                       SAMA DENGAN
  20. #======================================================
  21. $this->db->select('name, email');
  22. $this->db->where('username', 'supian');
  23. $this->db->get('users');
  24. #======================================================
  25.  
  26.  
  27.  
  28. #======================================================
  29. $where = array('where' => array('username' => 'supian', 'email' => 'privcodes@gmail.com'), 'or_where' => false);
  30. $this->query->QueryData('name, email', 'users', $where);
  31. #======================================================
  32. #                       SAMA DENGAN
  33. #======================================================
  34. $this->db->select('name, email');
  35. $this->db->where('username', 'supian');
  36. $this->db->where('email', 'privcodes');
  37. $this->db->get('users');
  38.  
  39. #======================================================
  40. $where = array('where' => array('username' => 'supian'), 'or_where' => array('email' => 'privcodes@gmail.com'));
  41. $this->query->QueryData('name, email', 'users', $where);
  42. #======================================================
  43. #                       SAMA DENGAN
  44. #======================================================
  45. $this->db->select('name, email');
  46. $this->db->where('username', 'supian');
  47. $this->db->or_where('email', 'privcodes');
  48. $this->db->get('users');
  49. #======================================================
  50.  
  51.  
  52. #======================================================
  53. $this->query->QueryData('users_id, contact_id, phone', 'users', false, array('join' => 'contact', 'contact.contact_id = users.users_id', 'type' => 'inner'));
  54. #======================================================
  55. #                       SAMA DENGAN
  56. #======================================================
  57. $this->db->select('users_id, contact_id, phone');
  58. $this->db->from('users');
  59. $this->db->join('contact', 'contact.contact_id = users.users_id', 'inner');
  60. $this->db->get();
  61.  
  62. #======================================================
  63. $this->query->QueryData('name, email', 'users', false, false, array('email' => 'id', 'type' => 'DESC'));
  64. #======================================================
  65. #                       SAMA DENGAN
  66. #======================================================
  67. $this->db->select('name, email');
  68. $this->db->order('email', 'DESC');
  69. $this->db->get('users');
  70. #======================================================
  71.  
  72.  
  73. #======================================================
  74. $this->query->QueryData('name, email', 'users', false, false, array('colum' => 'id', 'type' => 'DESC'), array('from' => '0', 'to' => 5));
  75. #======================================================
  76. #                       SAMA DENGAN
  77. #======================================================
  78. $this->db->select('name, email');
  79. $this->db->order('email', 'DESC');
  80. $this->db->limit(5,0);
  81. $this->db->get('users');
  82. #======================================================
  83.  
  84.  
  85.  
  86. #======================================================
  87. $where = array('where' => array('code' => 'ABCDEF'),'or_where' => false);
  88. $this->query->QueryData('status, balance', 'invite_code', $where);
  89. $numCode = $this->query->GetNumRows();
  90. $rowCode = $this->query->GetResult();
  91.  
  92. echo $numCode; // Menghasilkan jumlah row
  93. echo $rowCode->status; // Aktif
  94. echo $rowCode->balance; // 100 Koin
  95.  
  96. #======================================================
  97. #                       SAMA DENGAN
  98. #======================================================
  99. $this->db->select('status, balance');
  100. $this->db->where('code' => 'ABCDEF');
  101. $query = $this->get('invite_code');
  102. $numCode = $query->num_rows();
  103.  
  104. echo $numCode; // Menghasilkan jumlah row
  105.  
  106. foreach ($query->result() as $rowCode) {
  107.     echo $rowCode->status; // Aktif
  108.     echo $rowCode->balance; // 100 Koin
  109. }
  110.  
  111. #======================================================
  112. $this->query->InsertData('users', array('id' => 1, 'username' => 'supian'));
  113. #======================================================
  114. #                       SAMA DENGAN
  115. #======================================================
  116. $this->db->insert('users', array('id' => 1, 'username' => 'supian'));
  117. #======================================================
  118.  
  119.  
  120.  
  121. #======================================================
  122. $this->query->UpdateData('users', array('last_login' => '26 Juni 1997'), array('id' => 1));
  123. #======================================================
  124. #                       SAMA DENGAN
  125. #======================================================
  126. $this->db->where('id', 1);
  127. $this->db->update('users', array('last_login' => '26 Juni 1997'));
  128. #======================================================
  129.  
  130.  
  131. #======================================================
  132. $this->query->DeleteData('users', array('id' => 1));
  133. #======================================================
  134. #                       SAMA DENGAN
  135. #======================================================
  136. $this->db->where('id', 1);
  137. $this->db->delete('users');
  138. #======================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement