Join usage Analysis of CI framework database query, CI framework join usage
This paper describes the join usage of CI Framework database query. Share to everyone for your reference, as follows:
Use each ID in table A to query the information in the People table for this ID. The statements are as follows:
$this->db->from (' A '); $this->db->join (' B ', ' sites.id = b.ID ');
Use each ID in table A to query the information in table B for this ID.
Note The SQL conventions, if a column name is duplicated in two tables, you need to precede the column name with a table name and a "." No. Therefore sites.id in the position table is the sites of the table where the ID is located. When making a SQL multi-table query, it is best to uniquely identify the column name, which avoids ambiguity or makes you understand.
such as: You execute the following statement
$this->db->select (' * '); $this->db->from (' blogs '); $this->db->join (' comments ', ' comments.id = Blogs.id '); $query = $this->db->get ();
Equivalent to executing this SQL statement
SELECT * FROM blogs JOIN comments on comments.id = Blogs.id
If you want to use more than one connection in a query, you can call this function multiple times.
If you need to specify the type of JOIN, you can specify it by the third parameter of this function. Optional options include: left, right, outer, inner, left outer, and right outer.
$this->db->join (' comments ', ' comments.id = Blogs.id ', ' left ');//Generate: Left join comments on comments.id = Blogs.id
More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP Excellent Development Framework Summary", "thinkphp Getting Started", " Summary of common methods of thinkphp, "Introduction to Zend Framework Frame", "Introduction to PHP Object-oriented Programming", "Introduction to Php+mysql Database Operation" and "PHP common database Operation Skills Summary"
It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.
http://www.bkjia.com/PHPjc/1127851.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127851.html techarticle CI Framework database query Join usage analysis, CI framework join Usage This article describes the join usage of the CI Framework database query. Share to everyone for your reference, as follows: In a table ...