thinkphpHow to use sub-tables
I preset 10 tables, namely table_1, table_2, table_3....table_10
Partition is set in Model:
protected $partition = array(
'field' => 'id',
'type' => 'id',
'expr' => '',
'num' => 10,
);
Also used getPartitionTableName()
The official documentation says that the current data must be passed in. Then which data table should be actually operated according to the data analysis
And what is the current data that is passed in? The result of every experiment I have is a joint query! The current table name cannot be found!
------Solution--------------------
Your sub-table field is id (PS: T is good
PHP
Qkuan: 276167802, verification: csl)
Therefore, the data array passed to getPartitionTableName must contain an element with the associated key id
But his algorithm is a bit strange
$field = $data[$this->partition['field']];
switch($this->partition['type']) {
case 'id':
// 按照id范围分表
$step = $this->partition['expr'];
$seq = floor($field / $step)+1;
break;
.........
return $this->getTableName().'_'.$seq;
According to your settings, it seems that it should be 'type' => 'mod'
case 'mod':
// 按照id的模数分表
$seq = ($field % $this->partition['num'])+1;
break;
------Solution--------------------
Isn’t it the table name that you get with getPartitionTableName?
With the table name, wouldn’t it be the same as without dividing the table?
The above is the method of using thinkphp sub-table in this article. I hope this article will be helpful to the majority of php developers. Thank you for reading this article.
http://www.bkjia.com/PHPjc/621609.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621609.htmlTechArticlethinkphp How to use sub-tables I have preset 10 tables, namely table_1, table_2, table_3....table_10 The partition is set in the Model: protected $partition = array('field' => 'id','ty...