欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)的連貫操作、鏈?zhǔn)讲僮鲗?shí)例

 更新時(shí)間:2014年07月08日 10:01:13   投稿:junjie  
這篇文章主要介紹了PHP實(shí)現(xiàn)的連貫操作、鏈?zhǔn)讲僮鲗?shí)例,本文用一個(gè)數(shù)據(jù)庫(kù)操作類(lèi)作為實(shí)例,需要的朋友可以參考下

PHP中的連貫操作看起來(lái)的確很酷,也非常的方便代碼的閱讀,當(dāng)然了必須是在OOP中用才行,在過(guò)程化的程序中,就沒(méi)有必要用這種方法了。有實(shí)現(xiàn)這個(gè)方法的有用_CALL來(lái)實(shí)現(xiàn)的,而我下面寫(xiě)的這個(gè)例子,則不是用_call的,大家可以擴(kuò)展一下吧。

下面寫(xiě)的這個(gè)SQL語(yǔ)句組合類(lèi),主要是用于學(xué)習(xí)的,如果有同學(xué)想拿去用,請(qǐng)?jiān)偻晟埔幌隆?/p>

/*
 * SQL語(yǔ)句組合實(shí)例類(lèi),始發(fā)文章web開(kāi)發(fā)筆記
 * 學(xué)習(xí)用,非專(zhuān)業(yè)類(lèi)
 * */
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();
//輸出 SELECT * FROM testTable WHERE id=1 ORDER BY id DESC LIMIT 0,10

相關(guān)文章

最新評(píng)論