簡體   English   中英

如何插入最后一個id。 mysql_insert_id()不起作用

[英]How to get last id inserted. mysql_insert_id() not working

我在opencart版本2x工作。 我正在嘗試插入行的最后一個id。這個代碼適用於1.5x版本,但在2x中沒有返回任何內容

我的代碼:

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

您需要在OpenCart中使用它來獲取最后一個插入ID:

$this->db->getLastId()

從OpenCart用戶指南:

方法參考/ DB :: getLastId():返回上一個查詢為AUTO_INCREMENT列生成的ID。

$this->db->getLastId(); 此函數用於獲取最后插入的id

嘗試使用此方法$this->db->getLastId() ;

試試這個...

SELECT LAST_INSERT_ID();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM