PHP通过参数来生成MYSQL语句类.pdf
《PHP通过参数来生成MYSQL语句类.pdf》由会员分享,可在线阅读,更多相关《PHP通过参数来生成MYSQL语句类.pdf(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 PHP 通过参数来生成 MYSQL 语句类 2 作者:日期:个人收集整理 勿做商业用途 3 PHP 通过参数来生成 MYSQL 语句类 这个类可以通过具有参数的数组来构建 MySQL 查询语句。这个类可以通过指定的表和字段参数创建 SELECT,INSERT,UPDATE 和 DELETE 语句。这个类可以创建 SQL 语句的 WHERE 条件,像 LIKE 的查询语句,使用 LEFT JOIN 和ORDER 语句。例子:Result Generate Insertbr ;object=new MyLibSQLGen();object-clear_all_assign();/to refre
2、sh all property but it no need when first time execute object-setFields(fields);object-setValues(values);object-setTables(tables);if(!object-getInsertSQL())echo object-Error;exit;else sql=object Result;echo sql.”;echo”bResult Generate Update/b ;fields=Array(”name”,”address”,city”);values=Array(Fadja
3、r”,”Resultmang Raya Street ,”Jakarta”);tables=Array(”customer”);id=1;conditions 0 ”condition”=”id=id”;conditions 0 connection”=“;object-clear_all_assign();object setFields(fields);object setValues(values);object-setTables(tables);object-setConditions(conditions);if(!object-getUpdateSQL()echo object
4、Error;exit;else sql=object Result;echo sql.”;echo”Result Generate Delete/bbr”;tables=Array(”customer”);conditions 0 ”condition”=”id=1 ;conditions 0 ”connection”=OR ;conditions 1 ”condition”=”id=2”;conditions 1 connection”=”OR ;conditions 2 condition”=”id=4”;conditions 2 ”connection =“”;个人收集整理 勿做商业用途
5、 5 object-clear_all_assign();object-setTables(tables);object-setConditions(conditions);if(!object-getDeleteSQL()echo object-Error;exit;else sql=object Result;echo sql。”br ;fields=Array(”id”,name”,”address”,”city”);tables=Array(customer”);id=1;conditions 0 condition =”id=id”;conditions 0 ”connection
6、=“”;object clear_all_assign();object setFields(fields);object-setTables(tables);object-setConditions(conditions);if(!object-getQuerySQL()echo object-Error;exit;else sql=object-Result;echo sql.”br”;echo”bResult Generate List with search on all fields clear_all_assign();object setFields(fields);object
7、 setTables(tables);object-setSearch(search);if(!object-getQuerySQL()echo object Error;exit;else sql=object Result;echo sql。br”;echo”Fadjar Nurswanto ,”address =”Tomang Raya”);object-clear_all_assign();object setFields(fields);object-setTables(tables);object setSearch(search);if(!object getQuerySQL()
8、)echo object-Error;exit;else sql=object Result;echo sql。”类代码:?php /*Created By:Fadjar Nurswanto dbgDone(funct);return true;if(!is_array(conditions))this Error=className:funct nVariable conditions not Array”;return;for(i=0;i count(conditions);i+)this-Condition.=conditions i condition”.”.conditions i
9、”connection”。”;return true;function BuildLeftJoin()funct=”BuildLeftJoin”;className=get_class(this);if(!this getLeftJoin())this-Error=”className::funct nProperty LeftJoin was empty”;return;LeftJoinVars=this getLeftJoin();hasil=false;foreach(LeftJoinVars as LeftJoinVar)hasil.=”LEFT JOIN”。LeftJoinVar ”
10、table”;foreach(LeftJoinVar on as var)个人收集整理 勿做商业用途 8 condvar.=var ”condition”.”。var ”connection”。”;hasil。=”ON(”。condvar。)”;unset(condvar);this-ResultLeftJoin=hasil;return true;function BuildOrder()funct=BuildOrder”;className=get_class(this);if(!this getOrder())this-Error=”className::funct nProperty
11、Order was empty”;return;if(!this getFields()this-Error=”className::funct nProperty Fields was empty ;return;Fields=this-getFields();Orders=this getOrder();if(ereg(”,”,Orders))Orders=explode(”,”,Order);if(!is_array(Orders)Orders=Array(Orders);foreach(Orders as Order)if(!is_numeric(Order))this Error=c
12、lassName::funct nProperty Order not Numeric”;return;if(Order count(this-Fields))this-Error=”className::funct nMax value of property Sort is”。count(this-Fields);return;xorder。=Fields Order .”,”;this ResultOrder=”ORDER BY”.substr(xorder,0,1);个人收集整理 勿做商业用途 9 return true;function BuildSearch()funct=Buil
13、dSearch ;className=get_class(this);if(!this-getSearch()this Error=”className:funct nProperty Search was empty”;return;if(!this getFields()this-Error=”className::funct nProperty Fields was empty”;return;Fields=this getFields();xvalue=this-getSearch();if(is_array(xvalue))foreach(Fields as field)if(xva
14、lue field)Values=explode(”,xvalue field);foreach(Values as Value)hasil.=field。”LIKE ”。Value。”%OR ;if(hasil)hasil_final。=”(”.substr(hasil,0,-4)。”)AND”;unset(hasil);hasil=hasil_final;else 个人收集整理 勿做商业用途 10 foreach(Fields as field)Values=explode(”,xvalue);foreach(Values as Value)hasil。=field。”LIKE 。Valu
15、e.”OR”;this-ResultSearch=substr(hasil,0,-4);return true;function clear_all_assign()this-Result=null;this-ResultSearch=null;this-ResultLeftJoin=null;this-Result=null;this Tables=Array();this Values=Array();this Fields=Array();this-Conditions=Array();this Condition=null;this-LeftJoin=Array();this Sort
16、=”ASC”;this Order=null;this Search=null;this-fieldSQL=null;this-valueSQL=null;this partSQL=null;this Error=null;return true;function CombineFieldValue(manual=false)funct=”CombineFieldsPostVar ;个人收集整理 勿做商业用途 11 className=get_class(this);fields=this getFields();values=this getValues();if(!is_array(fie
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PHP 通过 参数 来生 MYSQL 语句
限制150内