我插入多張圖片到數據庫,但得到這樣的錯誤錯誤插入數組值到數據庫
當你有一個錯誤的SQL語法;檢查手冊中 對應於你的MySQL服務器版本正確的語法使用 接近0,1)VALUES(陣列,陣列)「在1號線
INSERT INTO
CompleteProjectImage
(0,1)VALUES(陣列, Array)
我在控制器中保存選定圖像的列表並將其傳遞給我的模型。
這是我的模型編碼插入數據庫。
public function create($projectDetails, $projectDescriptions, $projectImages){
$this->db->trans_begin();
$this->db->insert(self::$tblCompleteProject, $projectDetails);
$insert_id = $this->db->insert_id();
foreach ($projectDescriptions as $projectDescription) {
$insertDescription = array(
'project_id' => $insert_id,
'description' => $projectDescription,
);
}
$this->db->insert(self::$tblCompleteProjectDescription, $insertDescription);
foreach ($projectImages as $projectImage) {
$insertImage[] = array(
'project_id' => $insert_id,
'img_src' => $projectImage['img_src'],
);
}
$this->db->insert(self::$tblCompleteProjectImage, $insertImage); // Error inserting to this database
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
return ($this->db->affected_rows() != 1) ? false : true;
}
}
print_array($insertImage);
導致:
Array
(
[0] => Array
(
[project_id] => 5
[img_src] => 594a7f9a79285.jpg
)
[1] => Array
(
[project_id] => 5
[img_src] => 594a7f9a792851.jpg
)
)
嗯..它看起來像查詢生成器中該古老的框架不支持在單個查詢中進行多行插入。嘗試查找'insert()'方法的源代碼,或者在循環中執行插入操作。 –