CodeIgniter insert query will execute using following functions. They are $this->db->query() Insert With Query Bindings Standard Insert $this->db->insert_string() $this->db->insert_batch() Escaping Insert Queries Get Inserted ID Get Affected Rows $this->db->query() Program 1: $sql = “insert into tbl_user (name, age, groupname) values (‘codeigniter, 35, ‘Group 1’)”; $this->db->query($sql); Program 2: $data = array( ‘name’ = > $_POST[‘name’] , […]
Tag Archives: CodeIgniter Query
CodeIgniter insert query will execute using following functions. They are $this->db->query() Insert With Query Bindings Standard Insert $this->db->insert_string() $this->db->insert_batch() Escaping Insert Queries Get Inserted ID Get Affected Rows $this->db->query() Program 1: $sql = “insert into tbl_user (name, age, groupname) values (‘codeigniter, 35, ‘Group 1’)”; $this->db->query($sql); Program 2: $data = array( ‘name’ = > $_POST[‘name’] , […]
CodeIgniter Join query function is used to fetch the result from one or more tables. The join types are normal join, inner join, left join and right join. Normal Join Join With Condition Inner Join Left Join Right Join Normal Join $this->db->select(‘tbl_user.username,tbl_user.userid,tbl_usercategory.typee’); $this->db->from(‘tbl_user’); $this->db->join(‘tbl_usercategory’,’tbl_usercategory.usercategoryid=tbl_user.usercategoryid’); $query=$this->db->get(); $data=$query->result_array(); SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`type` FROM (`tbl_user`) JOIN `tbl_usercategory` ON […]
$this->db->query() Read & Write Query $this->db->simple_query() Set Prefixes For Table Set Dynamic Prefix For Table Protecting identifiers Escaping Queries (Security Practice) Query Bindings $this->db->query() To submit a query, use the following function: $this->db->query(‘YOUR QUERY HERE’); place raw SQL in the query() method $query = $this->db->query(“select * from users”); Pass query in a variable $sql = […]
CodeIgniter ‘SELECT’ query will execute using following functions. They are $this->db->query() $this->db->query() With Query Bindings $this->db->get() $this->db->get() Select The Fields $this->db->get() With Limit $this->db->get() With Offset,Limit $this->db->get() With select, from $this->db->get() With Where, Or_Where, Where_In, or_where_in, where_not_in $this->db->get_where() $this->db->get() With Like, or_like, not_like, or_not_like $this->db->get() With group_by $this->db->get() With having $this->db->get() With Order BY $this->db->select_max() […]
CodeIgniter ‘UPDATE’ query will execute using following functions. They are $this->db->update() $this->db->update_string() $this->db->update_batch() $this->db->update() $data = array( ‘name’ = > $_POST[‘name’] , ‘groupname’= > $_POST[‘groupname’], ‘age’ = > $_POST[‘age’] ); $this->db->where(‘id’, $_POST[‘id’]); $this->db->update(‘tbl_user’, $data); $this->db->update_string() Note: Values are automatically escaped, producing safer queries. $data = array( ‘groupname’= >$_POST[‘groupname’] ); $where = “status = ‘user'”; $str […]