整理一些demo和自己对AaronSaray写的PHP设计模式的理解。看完后,如果发现我的理解有误,请立即指出,感谢拍赞,求鞭笞/***DAO(DataAccessObjects)数据访问对象*--------------------------------***来自描述****数据访问对象设计模式描述了如何创建对象提供对任何数据源的透明访问**目的是解决以下两个具体问题:*1.重复*2.数据源抽象*数据访问对象模式提供了一个数据库抽象层*现在,主要处理代码应用程序不再考虑数据库引擎或表关系*调用此对象的公共方法将返回任何数据类型,而不管底层SQL所需的类型**========================================***应用场景****数据访问**------------------------------------**@version${Id}$*@authorShaoweiPu<54268491@qq.com>*/abstractclassbaseDao{/***[$_connection连接对象]*@var[类型]*/private$_connection;/***[__construct实例化数据库连接]*@authorShaoweiPu*@CreateTime2017-02-22T17:52:04+0800*/publicfunction__construct(){try{$this->_connection=new\PDO("mysql:dbname=mysql;host=localhost","root","pushaowei");$this->_connection->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);}catch(PDOException$e){die('error:'.$e->getMessage());}}/***[feachdescription]*@authorShaoweiPu*@CreateTime2017-02-22T18:01:48+0800*@return[type][description]*/publicfunctionfetch($value,$key=''){//SQL开始$sql='SELECT*FROM'.$this->_tablename.'哪里'.$key.'="'.$值。'"';//输出$dispose=$this->_connection->query($sql);返回$dispose->fetch(PDO::FETCH_ASSOC);}}classselectHandleextendsbaseDao{/***[$_tablename得到表名]*@varstring*/protected$_tablename='db';/***[getValuedescription]*@authorShaoweiPu*@CreateTime2017-02-22T18:06:58+0800*@param[类型]$值[描述]*@return[类型][描述]*/publicfunctiongetDbValue($value){$result=parent::fetch($value,'Host');返回$结果;}}$select=newselectHandle;var_dump($select->getDbValue('localhost'));/*+------------------------------------------------------------------|数组(大小=22)|'Host'=>string'localhost'(length=9)|'Db'=>字符串'sys'(长度=3)|'User'=>string'mysql.sys'(length=9)|'Select_priv'=>字符串'N'(长度=1)|'Insert_priv'=>字符串'N'(长度=1)|'Update_priv'=>字符串'N'(长度=1)|'Delete_priv'=>字符串'N'(长度=1)|'Create_priv'=>字符串'N'(长度=1)|'Drop_priv'=>字符串'N'(长度=1)|'Grant_priv'=>字符串'N'(长度=1)|'References_priv'=>字符串'N'(length=1)|'Index_priv'=>字符串'N'(长度=1)|'Alter_priv'=>字符串'N'(长度=1)|'Create_tmp_table_priv'=>string'N'(length=1)|'Lock_tables_priv'=>字符串'N'(长度=1)|'Create_view_priv'=>字符串'N'(长度=1)|'Show_view_priv'=>字符串'N'(长度=1)|'Create_routine_priv'=>字符串'N'(长度=1)|'Alter_routine_priv'=>字符串'N'(长度=1)|'Execute_priv'=>字符串'N'(长度=1)|'Event_priv'=>字符串'N'(长度=1)|'Trigger_priv'=>string'Y'(length=1)+-------------------------------------------------------------------*/