使用方法
$mysql = new sqlstr("table1") ;
$mysql->set("名称","值");
$mysql->set("name","1",true);
echo $mysql->insertSql();
class sqlstr
{
私有$param=array();
私有$表名;
function sqlstr($tablename)
{
$this->tablename = $tablename;
}
公共函数集($name,$value,$isnum=false){
$value = str_replace("'","''",$value);
$this->param[$name]=array($value,$isnum);
}
public function insertSql(){
$keys="";
$values="";
foreach($this->param as $key =>$value){
$keys = $keys . $键。 “,”;
if($value[1]){
$values = $values . $值[0] 。 “,”;
}其他{
$values = $values . “'”。 $值[0] 。 “',”;
}
}
if($keys!=""){$keys=substr($keys,0,strlen($keys)-1) ;}
if($values!= ""){$values=substr($values,0,strlen($values)-1) ;}
return "insert into " .$this->tablename ."($keys) value($values) ”;
}
public function updateSql($cond){
$group="";
foreach($this->param as $key =>$value){
$group .= $key . “=”;
if($value[1]){
$group.= $value[0] . “,”;
}其他{
$group.= "'" . $值[0] 。 “',”;
}
}
if($group!=""){$group=substr($group,0,strlen($group)-1) ;}
返回 "update " 。 $this->表名 ." 设置 $group where " . $条件;
}
}