如何使用 CodeIgniter 中的批量插入获取查询的最后插入 ID。我使用了代码$this->db->insert_id()
,但它返回了我第一个插入数组的 ID。我不能得到最后一个插入。
这是我所做的:
for ($x = 0; $x < sizeof($filtername); $x++) {
$orders[] = array(
'poid' => null,
'order_id' => $poid,
'item_desc' => $filtername[$x],
'item_qty' => $filterquantity[$x],
'item_price' => $filterprice[$x],
'total' => $filtertotal[$x],
'cash_on_delivery' => $val_delivery,
'is_check' => $val_check,
'bank_transfer' => $val_transfer,
'transaction_date' => $dateorder
);
}
$this->db->insert_batch('po_order', $orders);
echo $this->db->insert_id(); //will return the first insert array
我无法发现我的错误在哪里。我的最后一个选择是使用查询来获取它。我也这样做了mysql_insert_id()
,但总是返回 0。