Home  >  Article  >  Backend Development  >  Examples of ThinkPHP (million-level) data table technology

Examples of ThinkPHP (million-level) data table technology

WBOY
WBOYOriginal
2016-07-25 08:59:461649browse
Let me tell you about an example of ThinkPHP's built-in sub-table algorithm for processing millions of data. Friends in need can take a look.

Extract the code from thinkphp to see how others implement big data table splitting.

Data sheet: house_member_0 house_member_1 house_member_2 house_member_3

model:

class MemberModel extends AdvModel {
protected $partition = array('field'=>'username','type'=>'id','num'=>'4');
    public function getDao($data=array()) {
        $data = empty($data) ? $_POST : $data;
        $table = $this->getPartitionTableName($data);
        return $this->table($table);
    }
}

action:

class MemberAction extends BaseAction {
    public function login() {
        if($this->isPost()) {
            $this->validToken();
            $dao = D('Member')->getDao();
            $res = $dao->where('username = '.$_POST['username'])->find();
            // output 为自定义方法
            // $isAjax - bool
            $this->output(false);
        }
        $this->display();
    }
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn