用戶表量級過大 目的把用戶表分一百張:
下面是試例:
<?php
namespace app\index\controller;
class Index
{
public function index()
{
$uId = '123123';
$tabCount = 100;//分成100個表 表名user0-user99 下表從0開始
$res = $this->getStringHash($uId,$tabCount);
halt($res);
//1·100 會根據uid返回 剩下的就是業務邏輯了。
}
public function getStringHash($uId, $tabCount)
{
$unsign = sprintf('%u', crc32($uId));
if ($unsign > 2147483647) {
$unsign -= 4294967296;
}
return abs($unsign) % $tabCount;
}
}
//創建表
for ($i=0; $i <= 99; $i++) { Db::query("CREATE TABLE user$i 裏面是 創建表語句") }