CI Framework database query Join usage analysis, CI framework join Usage _php Tutorial

Source: Internet
Author: User

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 ...

  • 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.