Open Rudi-Batubara opened 6 years ago
// ..... // AFTER VALIDATION PROCESS
$user = (array)[ 'name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'born_date' => $this->input->post('born_date'), ];
$this->db->trans_strict(FALSE);
$this->db->trans_begin();
$this->db->insert('USER_TABLE', ['USER_DATA']);
if ($this->db->trans_status() !== FALSE) { $this->db->trans_commit();
echo "Success";
}
$error = $this->db->error();
$this->db->trans_rollback();
swicth($error['code']) { case 1071: echo "Maximum key length"; break; case 1067: echo "Invalid default value"; break; case 1064: echo "Not null exception"; break; case 1061: echo "Duplicate entry"; break; default echo "Unknown exception"; break; }
terima kasih koreksinya pak. tetapi apa nggak overkill pak menggunakan transaction mengingat hanya menggunakan 1 query dan itu hanya insert pak?
// ..... // AFTER VALIDATION PROCESS
$user = (array)[ 'name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'born_date' => $this->input->post('born_date'), ];
$this->db->trans_strict(FALSE);
$this->db->trans_begin();
$this->db->insert('USER_TABLE', ['USER_DATA']);
if ($this->db->trans_status() !== FALSE) { $this->db->trans_commit();
}
$error = $this->db->error();
$this->db->trans_rollback();
swicth($error['code']) { case 1071: echo "Maximum key length"; break; case 1067: echo "Invalid default value"; break; case 1064: echo "Not null exception"; break; case 1061: echo "Duplicate entry"; break; default echo "Unknown exception"; break; }