我正在使用 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()
方法引用/DB::getLastId():返回上一个查询为 AUTO_INCREMENT
列生成的 ID。
关于php - 如何获取最后插入的 ID。 mysql_insert_id() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35863383/