Home > Backend Development > PHP Tutorial > Implementation method of PHP class coherent operation_PHP tutorial

Implementation method of PHP class coherent operation_PHP tutorial

WBOY
Release: 2016-07-13 09:54:17
Original
1146 people have browsed it

Implementation method of PHP class coherent operation

The coherent operation in PHP looks really cool, and it is very convenient to read the code. Of course, it must be used in OOP. In procedural programs, there is no need to use this method. There is a useful _CALL to implement this method, but the example I wrote below does not use _call. You can expand it.

The SQL statement combination class written below is mainly for learning. If any students want to use it, please improve it.

/*
* SQL statement combination instance class, the original article web development notes
* www.chhua.com
* For learning purposes, non-professional
* */
class sql{
private $sql=array(from=>,
where=>,
order=>,
limit=>);

public function from($tableName) {
$this->sql[from]=FROM .$tableName;
return $this;
}

public function where($_where='1=1') {
$this->sql[where]=WHERE .$_where;
return $this;
}

public function order($_order='id DESC') {
$this->sql[order]=ORDER BY .$_order;
return $this;
}

public function limit($_limit='30') {
$this->sql[limit]=LIMIT 0,.$_limit;
return $this;
}
public function select($_select='*') {
return SELECT .$_select. .(implode( ,$this->sql));
}
}

$sql =new sql();

echo $sql->from(testTable)->where(id=1)->order(id DESC)->limit(10)->select();
//Output SELECT * FROM testTable WHERE id=1 ORDER BY id DESC LIMIT 0,10

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998011.htmlTechArticle Implementation method of PHP class coherent operation The coherent operation in PHP looks really cool, and it is also very convenient to code. Reading, of course, must be used in OOP. In procedural programs, just...
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