从thinkphp中抽取出来的代码,看看人家是如何实现大数据分表的。
数据表:
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(); } }