新建10張表,user_0,user_1,...user_9,方法不可串用,采用hash或取余法,獲取要操作的表名,取值用對應存值的方法
1.hash取余法
public function part_table(){ $id=uniqid(); //php生成唯一 uuid $str = crc32($id); //hash 算法轉換 $table_name = 'user_'.$str%10; //取余獲取 表名 $user['id']=$id; $user['age']='20'; $user['name']='小豬_'.time(); db($table_name)->insert($user); //插入數據庫 echo $table_name; }
2.hash
public function part_table(){ $id=uniqid(); //php生成唯一 uuid $str = crc32($id); //hash 算法轉換 $hash = substr($str, 0, 1); // 32位 與64位操作 有差別 $table_name = 'user_'.$hash; //獲取 表名 $user['id']=$id; $user['age']='20'; $user['name']='小豬_'.time(); db($table_name)->insert($user); //插入數據庫 echo $table_name; }
