This paper illustrates the common functions of the CI Framework AR database operation. Share to everyone for your reference, specific as follows:
1, the inquiry table record
$this->db->select (); Select the field of the query
$this->db->select_max ();
$this->db->select_min ();
$this->db->select_avg ();
$this->db->select_sum ();
$this->db->from (); Select Table Name
$this->db->join ();
$this->db->get (); The results of the query are
$this->db->get_where ();
$this->db->where ();
$this->db->or_where ();
$this->db->where_in ();
$this->db->or_where_in ();
$this->db->where_not_in ();
$this->db->or_where_not_in ();
$this->db->like ();
$this->db->or_like ();
$this->db->not_like ();
$this->db->or_not_like ();
$this->db->group_by ();
$this->db->distinct ();
$this->db->having ();
$this->db->or_having ();
$this->db->order_by ();
$this->db->limit ();
$this->db->count_all_results ();
2, add table record
3, change the record of the table
$this->db->set ();
$this->db->update ();
4, delete the table record
5, clear the table record
$this->db->empty_table ();
$this->db->truncate ();
6, the cache part
$this->db->start_cache ()
$this->db->stop_cache ()
$this->db->flush_cache ()
7. Result set
Result () //Returns an Object array Result_array ()//Returns a two-dimensional
array
row ()//returns an object
Row_array ()//returns a one-dimensional array
num_rows () ///Returns the number of rows in the query
num_fields ()///Returns the number of fields that the query results
free_result ()//Release the resource memory of the query
8. Auxiliary query function
$this->db->insert_id () //Get the ID just inserted
$this->db->affected_rows ()///modify or insert the number of rows affected
$this-> Db->count_all (); Total number of statistics records this function joins the Where condition is invalid
$this->db->last_query (); Last executed SQL statement
//Note the following two functions return only SQL statements that do not execute SQL statements
$data = array (' name ' => $name, ' email ' => $email, ' url ' => $u RL);
$str = $this->db->insert_string (' table_name ', $data);
$data = Array (' name ' => $name, ' email ' => $email, ' url ' => $url);
$where = "author_id = 1 and status = ' active '";
$str = $this->db->update_string (' table_name ', $data, $where); Returns the updated string in the correct format
PS: About CodeIgniter detailed use of skills can refer to the website online manual:
CodeIgniter 2.2.4 User's Guide:
http://shouce.jb51.net/codeigniter2.2/
CodeIgniter 3.0 User's Guide:
http://shouce.jb51.net/codeigniter3.0/
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on CodeIgniter framework.