Typecho-php $ db-> select ()-> from ()-> where ();

Source: Internet
Author: User
An object that calls a method after a method is executed. It first returns the first select () method and then executes the second from () method (), do you want to execute the following method? An object that is called after a method

How is the process executed? First, return the first select () method, then execute the second from () method, and then execute the following method?

Reply content:

An object that is called after a method

How is the process executed? First, return the first select () method, then execute the second from () method, and then execute the following method?

In fact, it is very simple. The method is to operate on an object attribute. In the end, all the results are returned. You can use this chained method. A simple example is like this:


  sql .= $str;        return $this;    }    public function from( $str = "" ) {        $this->sql .= $str;        return $this;    }    public function __toString() {        return $this->sql;    }}$db = new database();echo $db->select("abc")->from("def");

Https://github.com/typecho/typecho/blob/master/var/Typecho/Db/Query.php#L423
Look at this.

What you should say is a chain operation. The statements written in the question are just a simple query statement and must be executed.$db->query()Result set, similar to this$db->query($db->select()->from()->where()). In the preceding constructor statement, each method returns the object itself.return $thisSo you can continue to execute the following method.

Actually, the object of the current operation is returned,$thisIn this way, you can implement chained operations!

The @ override example is very vivid. To put it bluntly, the function continuously returns its own reference, and then the function continuously performs operations on its own members.
If you have doubts about chain operations, you can look at this, about db api introduction http://www.typechodev.com/index.php/archives/17/

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.