[英]How to get last id inserted. mysql_insert_id() not working
I am working in opencart version 2x. 我在opencart版本2x工作。 I am trying to get the last id of row inserted.This code working for 1.5x version but returning nothing in 2x
我正在尝试插入行的最后一个id。这个代码适用于1.5x版本,但在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;
You need to use this in OpenCart for getting last insert id: 您需要在OpenCart中使用它来获取最后一个插入ID:
$this->db->getLastId()
From OpenCart User Guide: 从OpenCart用户指南:
Method Reference / DB::getLastId(): Returns the ID generated for an AUTO_INCREMENT
column by the previous query. 方法参考/ DB :: getLastId():返回上一个查询为
AUTO_INCREMENT
列生成的ID。
$this->db->getLastId();
this function is used to get last inserted id 此函数用于获取最后插入的id
尝试使用此方法$this->db->getLastId()
;
试试这个...
SELECT LAST_INSERT_ID();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.