liumiuyong
1/18/2017 - 6:42 AM

php create table

php create table

<?php

for($i=0;$i<1024;$i++){
    $i = str_pad($i, 4, 0, STR_PAD_LEFT);

    $create_table_list[] = "CREATE TABLE `follows_{$i}` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '维持innodb性能的主键,同时用于排序',
  `uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关注者UID',
  `follow_uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '被关注者UID',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关注时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uid` (`uid`,`follow_uid`) USING BTREE COMMENT '唯一键,同时用于获取我的关注',
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='关注表,根据uid取模分1024表';";

    $create_table_list[] = "
CREATE TABLE `follows_me_{$i}` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '维持innodb性能的主键,同时用于排序',
  `uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关注者UID',
  `follow_uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '被关注者UID',
  `likes` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '喜欢数',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关注时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `follow_uid` (`follow_uid`,`uid`) USING BTREE COMMENT '唯一键,同时用于获取我的粉丝',
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='被关注表,根据follow_uid取模分128表';";
}
foreach($create_table_list as $create_sql){
    echo $create_sql."\n";
}
exit();