09-24-2020, 07:30 AM
Hi,
I have a pretty complex form that requires multiple table rows to be either inserted, updated or a combination of the two.
I was wondering if it is at all possible to use the $userModel->save() in conjunction with tranaction as this would be a very convenient way of updating my table without the need for a complex rollback function, something like?
Thanks in advance
I have a pretty complex form that requires multiple table rows to be either inserted, updated or a combination of the two.
I was wondering if it is at all possible to use the $userModel->save() in conjunction with tranaction as this would be a very convenient way of updating my table without the need for a complex rollback function, something like?
PHP Code:
protected $table = 'mytable';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $allowedFields = [
'column1', 'column2', 'column3', 'column4', 'column5'
];
public function addEditVals($vals) {
$db = db_connect();
$this->db->transStart();
foreach($vals as $valArray) {
$this->save($valArray);
}
$this->db->transComplete();
if ($this->db->transStatus() === FALSE) {
log_message('notice', '[ERROR] {file}-{line}, Failed to Add/Edit Table - '.session('user_name'));
return false;
}else{
log_message('notice', '[SUCCESS] {file}-{line}, Table Added/Updated - '.session('user_name'));
return true;
}
}
Thanks in advance
