php—在项目中用于选择查询的单个函数,其执行或加载时间是快是慢

vdgimpew  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(276)

我在为codeigniter项目工作。
我在codeignite project-->application->models中创建了一个“common\u model”php页面,并使用一个方法(getsinglerow)只从表中选择一行(像student、users、admin、employee这样的任何表)。前任。

public function getSingleRow($table_name,$where){

    $this->db->where($where);
    $query = $this->db->get($table_name);
    return $query->row();    
}
$where is using for columns where condition data.

我有第二个项目=>学生,用户,管理,员工在我的项目部分。每一节我都在做不同的模型页和不同的方法来选择查询。例如,对于学生应用程序->模型->学生模型php页面和方法是这样的。

public function getStudentSingleRow($where){
    $this->db->where($where);
    $query = $this->db->get('student_table');
    return $query->row();  
}

就像对模型页面和方法的所有部分(admin、users、employee)使用一样。
我的问题是哪种编码功能在第一个(1)或第二个(2)工作得更快?
如果我有11万用户,5万员工和10万学生在不同的表格和更多的表格中。我使用的是mysql服务器。

wqlqzqxt

wqlqzqxt1#

唯一的区别是在传递和存储变量时使用的内存量很少 table_name 否则两者在功能和速度方面是相同的。
$this->db->where->($where); 应该是 $this->db->where($where); .
当然,我会偏离第一种方法,因为它的可维护性较差,即特定的表模式更改。最好为每个人介绍一个模型 student , admin 等等。

相关问题