I'm doing an insert with Codeigniter 3 , in MySQL , which works fine, the idea is now to implement the rollback , but for some reason it doesn't.
This is my code:
$this->db->trans_strict(false);
$this->db->trans_start();
$this->usuario = $json['usuario'];
$this->clave = md5($json['claves']);
$this->perfil_id = $json['perfil_id'];
$this->estado = $json['estado'];
$this->db->insert('usuario', $this);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
return false;
} else {
$this->db->trans_commit();
return true;
}
I appreciate any suggestion.
using the functions
$this->db->trans_start();
and$this->db->trans_complete();
the rollback is automatic if the insert fails.The
$this->db->trans_rollback();
and functions$this->db->trans_commit();
are used to handle the transaction manually.Manual transaction example:
Ref: https://codeigniter.com/userguide3/database/transactions.html#running-transactions-manually