Get the Last added ID and Insert it to another Table as a foreign key

Get the last id from the database:-

$this->db->insert_id();

Suppose I have two table ‘product_sale’ and ‘customer_information’. I want to get last id from the ‘product_sale’ table and insert it to ‘customer_information’ table as a foreign key.

public function insertProductsale($data, $data_c) {

$this->db->insert('product_sale', $data);
$sale_id = $this->db->insert_id();
$data_c['sale_id'] = $sale_id;
return $this->db->insert('customer_information', $data_c);
}