This question already has an answer here:
- How to test if Ci successfully inserted data 2 answers
- Codeigniter Database Insert Failure 2 answers
i get some information from user and want to add it into two related tables in my database. i add first one and check it with 'insert_id' then add second one.
but problem is second 'insert_id' returns first tables inserted row id on failure. how can i check second insert query?
i'm using PHP 5, MySQL 5 and codeigniter 3
this is part of my controller:
$profile_result = $this->Profile_model->add($profile_data);
if ($profile_result)
{
$host_result = $this->Host_model->add([...]);
if (!$host_result)
echo 'error message';
}
Profile_model:
function add($options = array())
{
$this->db->insert("profile", $options);
return $this->db->insert_id();
}
and Host_model:
function add($options = array())
{
$this->db->insert("host", $options);
return $this->db->insert_id();
}
$host_result never gonna be false or 0.
but how can i check whether record added to host or not?
</div>