I hope to get answers based on experience and knowledge based on Codeigniter for this question. Lets say I have 10 tables in a database and I want to query all the rows in the 10 tables at the same time in the same controller. and there are two ways of doing this,
Case 01 - Use common query function like below,
Controller
sample_function(){
'table1_data' => $this->common_model->get_table( 'table1' ),
'table2_data' => $this->common_model->get_table( 'table2' ),
...
'table9_data' => $this->common_model->get_table( 'table9' ),
'table10_data' => $this->common_model->get_table( 'table10' )
}
and then in the common_model
function get_table( $table_name ){
$this->db->select()->from( $table_name );
$sql_stmt = $this->db->get();
return $sql_stmt->result();
}
so in this case the get_table( $table_name )
will run 10 times.
Case 02 - Use seperate functions for each 10 tables like below,
Controller
sample_function(){
'table1_data' => $this->common_model->get_table1(),
'table2_data' => $this->common_model->get_table2(),
...
'table9_data' => $this->common_model->get_table9(),
'table10_data' => $this->common_model->get_table10()
}
so that the common_model will be like this and here we have 10 functions not like use the same function in Case01
function get_table1()
{
$this->db->select()->from( 'table1' );
$sql_stmt = $this->db->get();
return $sql_stmt->result();
}
function get_table2()
{
$this->db->select()->from( 'table2' );
$sql_stmt = $this->db->get();
return $sql_stmt->result();
}
....
function get_table9()
{
$this->db->select()->from( 'table9' );
$sql_stmt = $this->db->get();
return $sql_stmt->result();
}
function get_table10()
{
$this->db->select()->from( 'table10' );
$sql_stmt = $this->db->get();
return $sql_stmt->result();
}
in this case 10 seperate functions run one time each.
It is obvious the Case 01 is the best when we consider code usability but my quiestion is when we consider the performance,
Which one is the best case in Codeigniter?
When it comes to Case 01, the get_table will run simultaniously or one at a time?
Whis case is the best for performance in CI?
Thnaks