Home  >  Article  >  Backend Development  >  How to use thinkphp sub-table? _PHP Tutorial

How to use thinkphp sub-table? _PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:18:49884browse

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 goodPHP 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.

www.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...
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