• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using updateBatch correctly

#1
I'm about to add this to my controller:

PHP Code:
foreach ($orders as $order) {
  $data['order_id'] = $order['id'];
  $data['status'] = $order['status'];
  $orderModel->save($data);


But I'm always concerned about this repeated calls to the DB ending on a syncing error or performance issue. Would this be the right moment to start using updateBatch?  If so, is this the way the controller would look like?

PHP Code:
foreach ($orders as $order) {
  $data[] = array(
  'order_id' => $order['id'],
  'status'=> $order['status']
  );
}
$result $orderModel->updateBatch($data,'order_id'); 

This is CI4 and Orders Model has no functions, only $allowedFields and $primaryKey defined.
Reply

#2
Looks okay to me.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.