The millions user data is processed using the thinkphp built-in table algorithm.
Data table:
House_member_0
House_member_1
House_member_2
House_member_3
In the 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);
}
}
Method in
Class Memberaction extends Baseaction {
Public Function login () {
if ($this->ispost ()) {
$this->validtoken ();
$dao = D (' member ')->getdao ();
$res = $dao->where (' username = '. $_post[' username ')->find ();
Output as a custom method
$isAjax-bool
$this->output (FALSE);
}
$this->display ();
}
}
/**
+----------------------------------------------------------
* Get the datasheet name of the table
+----------------------------------------------------------
* @access Public
+----------------------------------------------------------
* Data @param array $data operations
+----------------------------------------------------------
* @return String
+----------------------------------------------------------
*/
Public Function Getpartitiontablename ($data =array ()) {
Partitioning a data table
if (Isset ($data [$this->partition[' field ']]) {
$field = $data [$this->partition[' field ']];
Switch ($this->partition[' type ']) {
Case ' ID ':
List by ID range
$step = $this->partition[' expr '];
$seq = Floor ($field/$step) +1;
Break
Case ' Year ':
Table by year
if (!is_numeric ($field)) {
$field = Strtotime ($field);
}
$seq = Date (' Y ', $field)-$this->partition[' expr ']+1;
Break
Case ' mod ':
According to the ID modulus of the table
$seq = ($field% $this->partition[' num ']) +1;
Break
Case ' MD5 ':
According to the sequence of MD5
$seq = (ORD (substr (MD5 ($field), 0,1))% $this->partition[' num '] +1;
Break
Default:
if (function_exists ($this->partition[' type ')) {
Supports specifying function hashes
$fun = $this->partition[' type '];
$seq = (Ord (substr ($fun ($field), 0,1))% $this->partition[' num '] +1;
}else{
Table by the value of the first letter of the field
$seq = (Ord ($field {0})% $this->partition[' num ') +1;
}
}
return $this->gettablename (). ' _ '. $seq;
}else{
When you set a table field that is not in query criteria or data
To make a joint query, you must set partition[' num ']
$tableName = Array ();
For ($i =0 $i < $this->partition[' num '; $i + +)
$tableName [] = ' SELECT * from '. $this->gettablename (). ' _ '. $i;
$tableName = ' ('. Implode ("UNION", $tableName). As '. $this->name;
return $tableName;
}
}