<?php
/*
Created By : Fadjar Nurswanto <fajr_n@rindudendam.net>
DATE : 2006-08-02
PRODUCTNAME : class MyLibSQLGen
PRODUCTVERSION : 1.0.0
DESCRIPTION : class yang berfungsi untuk menggenerate SQL
DENPENCIES :
*/
class MyLibSQLGen
{
var $Result;
var $Tables=Array();
var $Values=Array();
var $Fields=Array();
var $Conditions=Array();
var $Condition;
var $LeftJoin=Array();
var $Search;
var $Sort="ASC";
var $Order;
var $Error;
function MyLibSQLGen(){}
function BuildCondition()
{
$funct="BuildCondition";
$className=get_class($this);
$conditions=$this->getConditions();
if(!$conditions){$this->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]["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["table"];
foreach($LeftJoinVar["on"] as $var)
{
@$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 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="$className::$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);
return true;
}
function BuildSearch()
{
$funct="BuildSearch";
$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(@$xvalue[$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
{
foreach($Fields as $field)
{
$Values=explode(" ",$xvalue);
foreach($Values as $Value)
{
@$hasil.=$field." LIKE '%".$Value."%' 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="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";
$className=get_class($this);
$fields=$this->getFields();
$values=$this->getValues();
if(!is_array($fields))
{
$this->Error="$className::$funct \nVariable fields not Array";
return;
}
if(!is_array($values))
{
$this->Error="$className::$funct \nVariable values not Array";
return;
}
if(count($fields)!=count($values))
{
$this->Error="$className::$funct \nCount of fields and values not match";
return;
}
for($i=0;$i<count($fields);$i++)
{
@$this->fieldSQL.=$fields[$i].",";
if($fields[$i] == "pwd" || $fields[$i] == "password" || $fields[$i] == "pwd")
{
@$this->valueSQL.="password('".$values[$i]."'),";
@$this->partSQL.=$fields[$i]."=password('".$values[$i]."'),";
}
else
{
if(is_numeric($values[$i]))
{
@$this->valueSQL.=$values[$i].",";
@$this->partSQL.=$fields[$i]."=".$values[$i].",";
}
else
{
@$this->valueSQL.="'".$values[$i]."',";
@$this->partSQL.=$fields[$i]."='".$values[$i]."',";
}
}
}
$this->fieldSQL=substr($this->fieldSQL,0,-1);
$this->valueSQL=substr($this->valueSQL,0,-1);
$this->partSQL=substr($this->partSQL,0,-1);
return true;
}
function getDeleteSQL()
{
$funct="getDeleteSQL";
$className=get_class($this);
$Tables=$this->getTables();
if(!$Tables || !count($Tables))
{
$this->dbgFailed($funct);
$this->Error="$className::$funct \nTable was empty";
return;
}
for($i=0;$i<count($Tables);$i++)
{
@$Table.=$Tables[$i].",";
}
$Table=substr($Table,0,-1);
$sql="DELETE FROM ".$Table;
if($this->getConditions())
{
if(!$this->BuildCondition()){$this->dbgFailed($funct);return;}
$sql.=" WHERE ".$this->getCondition();
}
$this->Result=$sql;
return true;
}
function getInsertSQL()
{
$funct="getInsertSQL";
$className=get_class($this);
if(!$this->getValues()){$this->Error="$className::$funct \nProperty Values was empty";return;}
if(!$this->getFields()){$this->Error="$className::$funct \nProperty Fields was empty";return;}
if(!$this->getTables()){$this->Error="$className::$funct \nProperty Tables was empty";return;}
if(!$this->CombineFieldValue()){$this->dbgFailed($funct);return;}
$Tables=$this->getTables();
$sql="INSERT INTO ".$Tables[0]." (".$this->fieldSQL.") VALUES (".$this->valueSQL.")";
$this->Result=$sql;
return true;
}
function getUpdateSQL()
{
$funct="getUpdateSQL";
$className=get_class($this);
if(!$this->getValues()){$this->Error="$className::$funct \nProperty Values was empty";return;}
if(!$this->getFields()){$this->Error="$className::$funct \nProperty Fields was empty";return;}
if(!$this->getTables()){$this->Error="$className::$funct \nProperty Tables was empty";return;}
if(!$this->CombineFieldValue()){$this->dbgFailed($funct);return;}
if(!$this->BuildCondition()){$this->dbgFailed($funct);return;}
$Tables=$this->getTables();
$sql="UPDATE ".$Tables[0]." SET ".$this->partSQL." WHERE ".$this->getCondition();
$this->Result=$sql;
return true;
}
function getQuerySQL()
{
$funct="getQuerySQL";
$className=get_class($this);
if(!$this->getFields()){$this->Error="$className::$funct \nProperty Fields was empty";return;}
if(!$this->getTables()){$this->Error="$className::$funct \nProperty Tables was empty";return;}
$Fields=$this->getFields();
$Tables=$this->getTables();
foreach($Fields as $Field){@$sql_raw.=$Field.",";}
foreach($Tables as $Table){@$sql_table.=$Table.",";}
$this->Result="SELECT ".substr($sql_raw,0,-1)." FROM ".substr($sql_table,0,-1);
if($this->getLeftJoin())
{
if(!$this->BuildLeftJoins()){$this->dbgFailed($funct);return;}
$this->Result.=" ".$this->ResultLeftJoin;
}
if($this->getConditions())
{
if(!$this->BuildCondition()){$this->dbgFailed($funct);return;}
$this->Result.=" WHERE (".$this->Condition.") ";
}
if($this->getSearch())
{
if(!$this->BuildSearch()){$this->dbgFailed($funct);return;}
if($this->ResultSearch)
{
if(eregi("WHERE",$this->Result)){$this->Result.=" AND ".$this->ResultSearch;}
else{$this->Result.=" WHERE ".$this->ResultSearch;}
}
}
if($this->getOrder())
{
if(!$this->BuildOrder()){$this->dbgFailed($funct)
没有合适的资源?快使用搜索试试~ 我知道了~
基于PHP的通过参数生成MYSQL语句的PHP类源码.zip
共2个文件
php:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 23 浏览量
2023-10-21
22:01:18
上传
评论
收藏 4KB ZIP 举报
温馨提示
基于PHP的通过参数生成MYSQL语句的PHP类源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于PHP的通过参数生成MYSQL语句的PHP类源码.zip (2个子文件)
132687319992401793
1325221266
class_mylib_SQLGen-1.0.php 10KB
example.php 3KB
共 2 条
- 1
资源评论
易小侠
- 粉丝: 6451
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab开发的全面详解LTE:MATLAB建模、仿真与实现-simulink.rar
- 自动驾驶定位系列教程二:系统架构.pdf
- 整站程序8优技巧网-8ujq.rar
- 世界各个国家或地区国际域名缩写
- 基于matlab开发的根据rvm回归模型自己编的matlab程序.rar
- 基于matlab开发的该程序为国内一所大学编写的LTE链路层仿真程序,根据LTE标准协议编写的,很容易看懂.rar
- 高效C++学生成绩管理系统:教育技术+C++17编程+数据管理+教务自动化
- 搜索链接要广告分类系统 v2.0-yad20.rar
- 基于matlab开发的Tipping的相关向量机RVM的回归MATLAB程序,有英文注释,可以运行.rar
- 一个点击正反转程序实例,可实现案件电机正反转
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功