-1

Getting empty value when calling getLastInsertID() in cakephp2.10

Mycode is

$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();

How to fix this? please help

Shamon S
  • 135
  • 1
  • 10

1 Answers1

1

As far as I know, Model::getLastInsertID() in Cake 2.x will return last inserted id only if that insert was made via Model methods, not plain SQL query. You should try this approach:

$this->Model->create();
$this->Model->set(...); //set your fields as needed
$this->Model->save();
$lastId = $this->Model->getLastInsertID();
Szymon
  • 1,385
  • 1
  • 8
  • 10