我在我的模型中编写了一个函数,用于在我的数据库中插入一个订单.我正在使用事务来确保所有提交,否则它将被回滚.
我的问题是笨没有显示任何数据库错误,但它是回滚事务,但然后返回TRUE了trans_status.但是,只有在订单有折扣时才会发生这种情况.如果订单没有折扣,一切都会提交并正常工作.
我目前正在使用CodeIgniter 3.19,PHP(7.2),mySQL(5.7)和Apache 2.4.(在Ubuntu 18.04上工作)
tbl_ordersorder_id并浏览每个订单产品(附件order_id)并插入产品tbl_order_products,order_product_id并将其附加到一组用户出勤选项并插入其中tbl_order_attendanceorder_id)并将其插入tbl_transactionsdiscount_redeem_count(可兑换折扣代码的数量)减少1.
[功能]:
public function add_order(Order $order, array $order_products, Transaction $transaction = NULL){
$this->db->trans_start();
$order->create_order_code();
$order_array = $order->create_order_array();
$this->db->insert('tbl_orders', $order_array);
$order_id = $this->db->insert_id();
$new_order = new Order($order_id);
foreach($order_products as $key=>$value){
$order_products[$key]->set_order($new_order);
$order_product_array = $order_products[$key]->create_order_product_array();
$this->db->insert('tbl_order_products', $order_product_array);
$order_product_id = $this->db->insert_id();
$product = $order_products[$key]->get_product();
switch ($product->get_product_class()){
case 'Iteration':
$this->db->select('module_id, …Run Code Online (Sandbox Code Playgroud) 我想使用codeigniter活动记录实现SQL语句.
UPDATE tags SET usage = usage+1 WHERE tag="java";
Run Code Online (Sandbox Code Playgroud)
如何使用Codeigniter活动记录实现此目的?
问候