Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在cakephp2.10中使用getLastInsertID时获取null_Php_Cakephp_Cakephp 2.5 - Fatal编程技术网

在cakephp2.10中使用getLastInsertID时获取null

在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

在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['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();