Analysis on join usage of CI framework database query; ci framework join usage _ PHP Tutorial

Source: Internet
Author: User
Analysis of join usage for CI framework database queries and ci framework join usage. Analysis of join usage in CI framework database query. ci framework join usage this article describes the join usage in CI framework database query. For your reference, the join usage analysis and CI framework join usage are as follows:

This article describes the join usage of the CI framework database query. We will share this with you 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 statement is as follows:

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

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

Note the SQL conventions. if a column name is repeated in two tables, you must add the table name and a "." number before the column name. Therefore, sites. id indicates that the table where id is located is sites. When performing SQL multi-table queries, it is best to uniquely identify the column name to avoid ambiguity and make it clear to yourself.

For example, run the following statement:

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

It is equivalent to executing this SQL statement.

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

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

To specify the JOIN type, you can use 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'); // generated: left JOIN comments ON comments. id = blogs. id

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.