2
I need to retrieve the last ID inserted in a table and pass this ID to the field of another function.
It is possible to recover in this way ?
$negociacao = array(
'id' => $neg->id,
'dt_negociacao' => $neg->dt_negociacao,
'atualizar' => $neg->atualizar,
'contrato_id' => $neg->contrato_id,
'id_finalizacao' => $neg->id_finalizacao,
'crud' => "C",
);
$this->db->insert('tbl_devedor_negociacao', $negociacao);
$negociacao_id = $this->db->insert_id(); //Armazenar ID recuperado
$this->set_negociacao_id($negociacao_id); // Setter váriável ID armazenado
// setter ID
private function set_negociacao_id($negociacao_id = null)
{
return $negociacao_id;
}
// getter ID
private function get_negociacao_id()
{
$this->set_negociacao_id();
}
// Atribuir ID recuperado Aqui
'negociacao_id' => $this->set_negociacao_id(),
Your get/set looks inverted and a little weird. This code gives some error?
– rray
No error. In function
set_negociacao_id
, if I place echo or print_r, it displays the last inserted ID, but when Return, it displays null.– Wagner Fillio
set
is to save/assign andget
to return. Theset
has areturn
and theget
does nothing...– rray
My intention is to retrieve this ID from an insert and assign this ID in a field from another function
– Wagner Fillio