thinkphp分表怎么使用
我预设了10个表 分别是 table_1、table_2、table_3....table_10
在model中设置了partition:
protected $partition = array( 'field' => 'id', 'type' => 'id', 'expr' => '', 'num' => 10, );
$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; case 'mod':
// 按照id的模数分表
$seq = ($field % $this->partition['num'])+1;
break;有了表名不就和不分表时一样操作了吗?
以上是本文关于thinkphp分表如何使用的方法,希望本文对广大php开发者有所帮助,感谢阅读本文。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号