1$data = array(
2 'title' => 'My title',
3 'name' => 'My Name',
4 'date' => 'My date'
5);
6
7$this->db->insert('mytable', $data);
8// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
9
1$this->db->select('ae_users.employee_id, ae_users.emp_name, ae_users.emp_name2, ae_users.emp_name3');
2 $this->db->from('ae_users');
3 $this->db->where_in('ae_users.employee_id',$employee_ids);
4 $this->db->_protect_identifiers = FALSE; // stop CI adding backticks
5 $order = sprintf('FIELD(ae_users.employee_id, %s)', implode(', ', $employee_ids));
6 $this->db->order_by($order);
7 $this->db->_protect_identifiers = TRUE;
8 $query =$this->db->get();
9 // echo '<pre>'; print_r($this->db->last_query());exit;
10 if ($query->num_rows()) {
11 return $query->result_array();
12 } else {
13 return 0;
14 }
1$data = [
2 'title' => $title,
3 'name' => $name,
4 'date' => $date
5];
6
7$builder->where('id', $id);
8$builder->update($data);
9// Produces:
10//
11// UPDATE mytable
12// SET title = '{$title}', name = '{$name}', date = '{$date}'
13// WHERE id = $id
14
1$data = array(
2 'title' => $title,
3 'name' => $name,
4 'date' => $date
5);
6
7$this->db->where('id', $id);
8$this->db->update('mytable', $data);
1$this->db->like('title', 'match'); $this->db->or_like('body', $match);
2// WHERE `title` LIKE '%match%' ESCAPE '!' OR `body` LIKE '%match%' ESCAPE '!'
3
1$this->db->select('*')->from('my_table')
2 ->group_start()
3 ->where('a', 'a')
4 ->or_group_start()
5 ->where('b', 'b')
6 ->where('c', 'c')
7 ->group_end()
8 ->group_end()
9 ->where('d', 'd')
10->get();
11
12// Generates:
13// SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'
14