I am working in opencart version 2x. I am trying to get the last id of row inserted.This code working for 1.5x version but returning nothing in 2x
My code:
$this->db->query("INSERT INTO `" . DB_PREFIX . "endicia_label_info` SET order_id = '$orderID',postage_balance = '$postage_balance',file_name='$fileName',dte_created_date_time = NOW(),tracking_no='$tracking_no',final_postage = '$final_postage',mail_type='$Mailtype',mail_class='$ClassMail',label_size='$labelimgsize',label_pieces='$labelpieces',labelname='$labelname',Status='$Status'");
$label_id = mysql_insert_id();
return $label_id;
Try with this method $this->db->getLastId()
;
You need to use this in OpenCart for getting last insert id:
$this->db->getLastId()
From OpenCart User Guide:
Method Reference / DB::getLastId(): Returns the ID generated for an AUTO_INCREMENT
column by the previous query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With