最近看了个大佬写的PHP项目,在此膜拜下。
其中发下如下几句:
public function autoUpdate($id,$data){
$where = " where {$this->fields['Key']} = '{$id}'";
$sql = "update {$this->getTable()} set ";
foreach($data as $key => $value){
$sql .= $key . '="' . $value . '",';
}
$sql = rtrim($sql,',') . $where;
return $this->exec($sql);
}
public function autoInsert($data){
$keys = $values = '';
foreach($this->fields as $k => $v){
if($k == 'Key') continue;
if(array_key_exists($v,$data)){
$keys .= $v . ',';
$values .= "'" . $data[$v] . "',";
}
}
$keys = rtrim($keys,',');
$values = rtrim($values,',');
$sql = "insert into {$this->getTable()} ({$keys}) values({$values})";
return $this->exec($sql);
}
从中可以知道,连int型,就可以使用单引号,赋值。在此测试了下,如下表:
SQL语句如下:
INSERT INTO b_test(b_int, b_float, b_bInt, b_tInt, b_string) VALUES('1', '1.1', '111', '1', 'hello111')
如下:
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://it1995.blog.csdn.net/article/details/122407733
内容来源于网络,如有侵权,请联系作者删除!