1 class createTableAction{
2 public function index(){
3 $dateSuffix = date('Y-m');
4 $checkTable = $dateSuffix.'statistics';
5 $res = $this->checkTables($checkTable);
6 if(!$res){
7 $checkTable = $this->createTable($checkTable);
8 }
9 }
10 //检测数据表是否存在
11 protected function checkTables($tables){
12 $tables = date('Y-m').'statistics';
13 $sql = "show tables like '{$tables}'";
14 $res = M()->query($sql);
15 if($res){
16 return true;
17 }else{
18 return false;
19 }
20 }
21 //建立数据表
22 private function createTable($tables){
23 $sql = "
24 create table if not exists `{$tables}`(
25 `id` bigint(20) not null primary key auto_increment,
26 `is_show` smallint(1) default 0
27 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
28 M()->query($sql);
29 //echo M()->getLastsql();
30 return $table;
31 }
32 }