
批改狀態(tài):合格
老師批語:
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'=>'空調(diào)','description'=>'格力空調(diào)'])
->update();
echo Db::table('T_product')
->where(['id'=>10])
->delete();
echo Db::table('T_product')
->Data(['proid'=>'120058','proname'=>'平板','price'=>9988,'description'=>'平板2'])
->insert();
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號