Idea: The chain syntax is the object call method after the assignment operation returns an object, then you can call the method, the last method to return a specific SQL statement
<?phpclass sql{ Private $sql =array ("from" and "" ", " 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= ') { $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 ()->select () ;//Output SELECT * from TestTable WHERE id=1 ORDER by ID DESC LIMIT 0,10?>
PHP chained syntax