批改状态:合格
老师批语:
public function Data($Data){$str = '';if (count($Data) > 0) {foreach ($Data as $k => $v) {$str .= ' , ' . $k . '= "' . $v.'"';}$str = substr($str, 2);}$this->opts['Data'] = " $str";return $this;}
public function update(){$sql = 'UPDATE ' .$this->table .' SET ';$sql .= $this->opts['Data']??null;$sql .= $this->opts['where']??die('禁止无条件删除');$stmt = $this->db->prepare($sql);$res = $stmt->execute();return $stmt->rowCount();}
public function delete(){$sql = 'DELETE FROM '.$this->table;$sql .= $this->opts['where']??die('禁止无条件删除');$stmt = $this->db->prepare($sql);$stmt->execute();return $stmt->rowCount();}
public function insert(){$sql = 'INSERT '.$this->table.' SET ';$sql .= $this->opts['Data'];$stmt = $this->db->prepare($sql);$stmt->execute();return $stmt->rowCount();}
echo Db::table('T_product')->where(['id'=>1])->Data(['proname'=>'空调','description'=>'格力空调'])->update();echo Db::table('T_product')->where(['id'=>10])->delete();echo Db::table('T_product')->Data(['proid'=>'120058','proname'=>'平板','price'=>9988,'description'=>'平板2'])->insert();
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号