Home > Backend Development > PHP Tutorial > CI framework database query join usage analysis, ci framework join usage_PHP tutorial

CI framework database query join usage analysis, ci framework join usage_PHP tutorial

WBOY
Release: 2016-07-12 08:52:11
Original
841 people have browsed it

Analysis of join usage in CI framework database query, ci framework join usage

The examples in this article describe the join usage in CI framework database query. Share it with everyone for your reference, the details are as follows:

Use each ID in table A to query the information of this ID in the people table. The sentence is as follows:

$this->db->from('A');
$this->db->join('B', 'sites.id = B.id');

Copy after login

Use each ID in table A to query the information of this ID in table B.

Pay attention to the SQL convention. If a column name is repeated in two tables, you need to add the table name and a "." sign before the column name. So sites.id in the location table means that the table where the id is located is sites. When performing SQL multi-table queries, it is best to uniquely identify column names. This can avoid ambiguity and make it clear to you.

For example: you execute the following statement

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');
$query = $this->db->get();

Copy after login

Equivalent to executing this sql statement

SELECT * FROM blogs JOIN comments ON comments.id = blogs.id

Copy after login

If you want to use multiple connections in the query, you can call this function multiple times.

If you need to specify the type of JOIN, you can specify it through the third parameter of this function. Options include: left, right, outer, inner, left outer, and right outer.

$this->db->join('comments', 'comments.id = blogs.id', 'left');
// 生成: LEFT JOIN comments ON comments.id = blogs.id

Copy after login

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127851.htmlTechArticleAnalysis of join usage in CI framework database query, ci framework join usage This article explains the join usage in CI framework database query with examples . Share it with everyone for your reference, the details are as follows: Use Table A...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template