Home > Backend Development > PHP Tutorial > update failed Insert and Update statement construction classes for PHP newbies

update failed Insert and Update statement construction classes for PHP newbies

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:48:23
Original
1010 people have browsed it

使用方法

复制代码 代码如下:


$mysql = new sqlstr("table1");
$mysql->set("name","value");
$mysql->set("name","1",true);
echo $mysql->insertSql();


复制代码 代码如下:


class sqlstr
{
private $param=array();
private $tablename;
function sqlstr($tablename)
{
$this->tablename = $tablename;
}
public function set($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 . $key . ",";
if($value[1]){
$values = $values . $value[0] . ",";
}else{
$values = $values . "'" . $value[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) values($values)";
}
public function updateSql($cond){
$group="";
foreach($this->param as $key =>$value){
$group .= $key . "=";
if($value[1]){
$group.= $value[0] . ",";
}else{
$group.= "'" . $value[0] . "',";
}
}
if($group!=""){$group=substr($group,0,strlen($group)-1) ;}
return "update " . $this->tablename ." set $group where " . $cond;
}
}

以上就介绍了update failed PHP新手用的Insert和Update语句构造类,包括了update failed方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
mysqli cannot update data
From 1970-01-01 08:00:00
0
0
0
apache restart failed
From 1970-01-01 08:00:00
0
0
0
add failed
From 1970-01-01 08:00:00
0
0
0
git failed to delete branch
From 1970-01-01 08:00:00
0
0
0
Why root login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template