/**
* 批量插入(如果資料已經存在,刪除原資料)注意$dataList中必須包含PRIMARY KEY或一個UNIQUE索引
* @param $dataList
* @return bool
*/
public function replace($dataList)
{
$keyList = array_keys(reset($dataList));
$keyStr = implode(",", $keyList);
$sql = "replace into " . $this->table . "($keyStr)" . " values";
foreach ($dataList as $item) {
$sql .= "('" . implode("','", array_values($item)) . "'),";
}
$sql = substr($sql, 0, -1);
$res = DB::connection($this->connection)->insert($sql);
return $res;
}
插入漢字會亂碼(插入資料庫時自動過濾了’'):解決方法 addslashes()處理下資料
本作品採用《CC 協議》,轉載必須註明作者和本文連結