Controller
$date=date("Y-d-m");
$succes=$this->pl->insert_ad($brandID,$model,$price,$year,$picture,$resized,$fuels,$id_usera,$date);
型号
public function insert_ad($brand,$model,$price,$year,$picture,$resized,$fuels,$date)
{
$sql1="INSERT INTO `ads`(`model`, `year`, `price`, `photo`, `date`, `resized_photo`, `id_fuel`, `id_brand`)
VALUES ('".$model."','".$year."','".$price."','".$picture."','".$date."','".$resized."','".$fuels."','".$brand."')";
$this->db->query($sql1);
return $this->db->insert_id();
}
我用 print_r($date)
打印它并显示 2016-03-16
,我现在真的不明白为什么它不会像其他任何东西一样插入。
最佳答案
I just tried this minutes ago and it worked! ^_^
$d = date("Y-m-d");
$t = date("h:i:s");
$this->db->set($this->col_prefix.'customer_id', $_POST['customer_id']);
$this->db->set($this->col_prefix.'total_amount', $_POST['total_amount']);
$this->db->set('date', "'".$d."'");
$this->db->set('time_in', "'".$t."'");
$this->db->set('status', 1);
$this->db->insert('sln_transactions');
but haven't tried it yet in array :) hope this could help.
关于php - 我无法将日期从 codeigniter 插入到 mysql DATE 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36029463/