在cakephp2.10中使用getLastInsertID时获取null
在cakephp2.10中调用getLastInsertID()时获取空值 麦可德是在cakephp2.10中使用getLastInsertID时获取null,php,cakephp,cakephp-2.5,Php,Cakephp,Cakephp 2.5,在cakephp2.10中调用getLastInsertID()时获取空值 麦可德是 $this->query("INSERT INTO $savedtbl(ref_name,productdetails_id,users_id,type,image,saved_date,template_name) VALUES('$ref_name',{$paramsArray['Customimage']['productdetail_id']},'$uid','{$paramsArray['Cus
$this->query("INSERT INTO $savedtbl(ref_name,productdetails_id,users_id,type,image,saved_date,template_name) VALUES('$ref_name',{$paramsArray['Customimage']['productdetail_id']},'$uid','{$paramsArray['Customimage']['front_rear']}','$editedImg','$date','$template_name')");
$lastid = $this->getLastInsertID();
如何解决这个问题?请帮助据我所知,Cake 2.x中的
模型::getLastInsertID()
仅当上次插入的id是通过模型方法而不是普通SQL查询进行插入时才会返回。您应该尝试以下方法:
$this->Model->create();
$this->Model->set(...); //set your fields as needed
$this->Model->save();
$lastId = $this->Model->getLastInsertID();