PHP is the core idea of chain operation, and the core idea of PHP chain-type
The implementation of the PHP chain-type operation
Copy the Code code as follows:
$db->where ()->limit ()->order ();
Create a database.php under Common.
The core of chain operation is the following: return $this at the end of the method;
database.php:
<?phpnamespace common;class database{ function where ($where) { return $this; The core of the chain approach lies in the following: return $this } Function Order ($order) {return $this after each method ; } function Limit ($limit) { return $this; }}
index.php:
<?phpdefine (' BASEDIR ', __dir__); Defines the root directory constants include BASEDIR. ' /common/loader.php '; Spl_autoload_register (' \\common\\loader::autoload '); $db = new \common\database (); Traditional operations require multiple lines of code implementation//$DB->where (' id = 1 ');//$db->where (' name = 2 ');//$db->order (' id desc ');//$db->limit (10) ;//using chained operation, a line of code solves the problem $db->where (' id = 1 ')->where (' name = 2 ')->order (' id desc ')->limit (10);
When using chained operations, the IDE (NetBeans will give you an automatic hint):
http://www.bkjia.com/PHPjc/1021093.html www.bkjia.com true http://www.bkjia.com/PHPjc/1021093.html techarticle PHP to implement the core concept of chain operation, PHP chain-like core idea of the implementation of the PHP chain operation code is as follows: $db-where ()-limit ()-order (); Create database.php under Common. Chain ...