_php example of common function Summary of CI framework AR database operation

Source: Internet
Author: User
Tags codeigniter zend framework

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

$this->db->insert ();

3, change the record of the table

$this->db->set ();
$this->db->update ();

4, delete the table record

$this->db->delete ();

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.