Repository: wintercoder/datamaker Branch: master Commit: c42e12258dc1 Files: 9 Total size: 78.7 KB Directory structure: gitextract_0vul5z6j/ ├── LICENSE ├── README.MD ├── README_EN.MD ├── conf/ │ ├── common.ini │ └── local.ini ├── gensql.php ├── index.php ├── index_en.php └── sqlparse.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2018 wintercoder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.MD ================================================ # 在线MYSQL测试数据生成工具 根据SQL表结构生成Mysql测试数据,根据字段名猜测类型,生成默认值 [English Readme](./README_EN.MD) ## 生成规则 普通规则见[官网](http://www.datamaker.online/),此处讲个规则的组合使用 **自增日期(组自增) + 常量列表(组模式)** 使用场景: 一个肯德基总店下有一堆子店,希望生成[每个子店每天]的数据,一行记录包含一个店一天的汇总数据 使用方法: 在子店ID 字段上选择 `常量列表(组模式)` 用逗号分隔写上各店的ID,日期选择 `自增日期(组自增)` 即可 **Unique Key** 有 `UNIQUE KEY (user_id,platform) ` 的情况 方案一: 这种platform只有1和2的可以考虑使用 给 `platform` 选 `常量列表(组模式)` 填 `1,2`,然后user_id选自增之类保证不重就OK。 方案二: 选择重复Key选项,测试数据一般跳过就好,注意选 `REPLACE INTO` 可能出现 `AUTO_INCREMENT` + 2 的情况 ## 个性化 你可以通过部署到自己的服务器上,对一些字段进行默认值配置,非常**适合公司内网** 部署也方便,代码里无任何框架依赖,能跑PHP就行 ### 配置 `/conf/common.ini` 为通用配置 `/conf/local.ini` 为个性化配置,适合不宜暴露的默认值,如测试账号ID等,该文件已加入 `.gitignore` 里,如果发现不生效则跑下命令 `git update-index --assume-unchanged conf/local.ini` 配置样例: ``` [0] key = index_day method = INCR_DAY value = 20180301 way = match [1] key = url method = RAND_PIC_URL value = 300,400 way = search ``` `key` : 字段名 `method` : 生成规则,如下表 `value` : 给前端的输入框值 `way` : 输入的key跟配置文件的key匹配规则,目前支持 `match` 完全相等、`search` 字符串包含,默认为`match` | 规则英文 | 中文 | 参数 | |----------|------|------| | INCR_INT | 自增int | from : 从from开始自增,步长1 | RAND_INT | 随机int | from,to : 生成[from,to]闭区间整数 | RAND_FLOAT | 随机浮点 | from,to,round : 生成[from,to]闭区间浮点,保留round位小数,这三个参数都是整数 | INCR_DAY | 日期自增 | from : 从from开始自增,步长1天,格式20180304 | INCR\_DAY\_GROUPLY | 日期自增(组模式) | 同上,但每组值里的这个日期不变,下条SQL才变 | RAND_TIMESTAMP | 随机时间戳 | from,to : 生成[from,to]这些天里的秒级时间戳,如 20180304,20180305 | RAND\_TIMESTAMP\_MYSQL | 随机时间(Mysql格式) | from,to : 生成[from,to]这些天里的秒级时间,格式:2018-04-07 18:08:34 | IGNORE | 不生成该列 | | CONST_STR | 常量 | 常量值 | CONST\_STR\_LIST | 常量列表(组模式) | 输入 a,b,每条SQL都输出 a,b,此时组数固定 | RAND_STR | 随机串 | length : 英文串长度 | RAND\_STR\_LIST | 随机串(指定列表) | a,b,c : 该字段只出现a,b,c之一,可重复出现 | INCR\_STR\_SUFFIX | 前缀+自增数字 | 输入 小王,输出 小王1,小王2,用于人名等 | RAND\_PIC\_URL | 图片地址 | width,height : 图片的宽高 ## 添加新生成规则流程 假设叫 rand_what 1. 前端 `index.php` `getDefaultValueByMethod()` 增加该规则的默认值 `getHoverContent()` 增加该规则的hover文案 `fillTabelWithData()` 增加对应代码 2. 后端 `gensql.php` `ValueGenerator` 类里新增 `randWhat()` 函数就行, 即下划线转驼峰 ## License **The MIT License** ================================================ FILE: README_EN.MD ================================================ # Online Sql Test Data Generator Generate sql test data by Mysql table structure Input: ``` CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `name` varchar(20) NOT NULL , PRIMARY KEY (`id`), ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ; ``` Output: ``` INSERT INTO `student (user_id,name) VALUES ('10001','John1'),('10002','John2'); INSERT INTO `student (user_id,name) VALUES ('10003','John3'),('10004','John4'); ``` **[Try It Now ](http://datamaker.online/index_en.php)** ## Individuation You can deploy this project on your server to set default value for frequently used fields, good for local area network like company Easy to deploy: It only require PHP (without any framework) and webserver ### Config `/conf/common.ini` is common config `/conf/local.ini` is personal config, good for same private value like test account. For safe, you should run `git update-index --assume-unchanged conf/local.ini` to avoid traced to git Sample: ``` [0] key = index_day method = INCR_DAY value = 20180301 way = match [1] key = url method = RAND_PIC_LIST value = 300,400 way = search ``` `key` : field name `method` : generate rule in the following table `value` : default value for front-end `way` : `match`:match this config if the input key is equals to key ; `search` match this config if the input key contains this key; the defalut value is `match` | Rule Method | Description | Parameter | |----------|------|------| | INCR_INT | auto increment integer | `from` : increase from `from` | RAND_INT | random int | `from,to` : random in interval `[from,to]` | RAND_FLOAT | random float | `from,to,round` : Random in interval `[from,to]` , retains `round` digits after the decimal point | INCR_DAY | increment day | `from` : increase from `from` with format 20180304 | INCR\_DAY\_GROUPLY | increment day (grouply same) | same as above,but the value is same in the same group | RAND_TIMESTAMP | random timestamp | `from,to` : timestamp in day `[from,to]`, input format is 20180304,20180305 | RAND\_TIMESTAMP\_MYSQL | random time (Mysql) | `from,to` : same as above,but the result format is 2018-04-07 18:08:34 | IGNORE | ignore this column | | CONST_STR | const value | | CONST\_STR\_LIST | const (group list) | `a,b`: every group in sql will output `a,b` | RAND_STR | random string | `length` : the length of string with alphabet | RAND\_STR\_LIST | random string in list | `a,b,c` : random pick one in `a,b,c` | INCR\_STR\_SUFFIX | Prefix + Number (Incr) | `test` : it will ouput test1,test2,test3 ... | RAND\_PIC\_URL | picture url | `width,height` : the width and height of url ## How to add new generator When you add a method call `rand_what` 1. Frontend: `index.php` `getDefaultValueByMethod()` add the default value `getHoverContent()` add the hover content `fillTabelWithData()` modify it 2. Backend`gensql.php` Add the function call `randWhat()` In class `ValueGenerator` ( Camel-Case of `rand_what` ) ## License **The MIT License** ================================================ FILE: conf/common.ini ================================================ [0] key = avatar method = RAND_PIC_URL value = 300,400 way = search [1] key = photo method = RAND_PIC_URL value = 300,400 way = search [2] key = picture method = RAND_PIC_URL value = 300,400 way = search [3] key = url method = RAND_PIC_URL value = 300,400 way = search [4] key = time method = RAND_TIMESTAMP value = 20180407,20180408 way = search [5] key = phone method = RAND_INT value = 15602000001,15602009999 way = search [6] key = insert_day method = INCR_DAY_GROUPLY value = 20180301 way = match [7] key = index_day method = INCR_DAY value = 20180301 way = match [8] key = status method = RAND_STR_LIST value = 0,1 way = search [9] key = data_day method = INCR_DAY_GROUPLY value = 20180301 way = match [10] key = is_ method = RAND_INT value = 0,1 way = search [11] key = flag method = RAND_INT value = 0,1 way = search [12] key = score method = RAND_INT value = 0,100 way = search ================================================ FILE: conf/local.ini ================================================ ================================================ FILE: gensql.php ================================================ randTimestamp($input,$groupSize); foreach ($ret as &$item){ $item = date("Y-m-d H:i:s",$item); } return $ret; } /** * 常量 * @param $input * value 常量值 * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function constStr($input,$groupSize){ return explode('$#$',str_repeat($input.'$#$',$groupSize)); } /** * 常量列表 * @param $input * value 常量值 * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function constStrList($input,$groupSize){ $input = !empty($input) ? $input : '百度$#$阿里$#$腾讯'; return explode('$#$',$input); } /** * 随机字符串(字符集:大小写字母) * @param $input array * length 长度 * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function randStr($length,$groupSize) { $ret = []; $count = 0; while ($count++ < $groupSize) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $ranStr = ''; for ($i = 0; $i < $length; $i++) { $ranStr .= $characters[rand(0, strlen($characters) - 1)]; } $ret []= $ranStr; } return $ret; } /** * 在字符串列表里 随机,全局可重复 * @param $input array * length 长度 * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function randStrList($input,$groupSize) { $input = !empty($input) ? $input : 'ofo,mobike'; $value = explode(',',$input); $ret = []; $count = 0; while ($count++ < $groupSize) { $ranStr = $value[rand(0, count($value) - 1)]; $ret []= $ranStr; } return $ret; } /** * 自增中文,根据 前缀+1 这种,如程序员1,程序员2 * @param $input array * pre_str 前缀 * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function incrStrPrefix($input,$groupSize,$sqlCounter) { $pre = !empty($input) ? $input : '测试店'; $inputArr['from'] = 1; $intArr = $this->incrInt($inputArr,$groupSize,$sqlCounter); $ret = []; foreach ($intArr as $intVal){ $str = $pre . $intVal; $ret []= $str; } return $ret; } /** * 随机图片,目前是 http://lorempixel.com/ * 也可以考虑用百度的 http://image.baidu.com/channel/listjson?pn=0&rn=30&tag1=%E7%BE%8E%E5%A5%B3&tag2=%E5%85%A8%E9%83%A8&ie=utf8 * @param $input * @param $groupSize int 每组多少条合并成一个数组,也是该次函数返回的数组大小 * @return array */ public function randPicUrl($input,$groupSize){ $exp = explode(',',$input); $width = !empty($exp[0]) ? intval($exp[0]) : 300; $height = !empty($exp[1]) ? intval($exp[1]) : 300; $url = "http://lorempixel.com/{$width}/{$height}/"; return explode(',',str_repeat($url.',',$groupSize)); } } class WorkHandler{ // /** // * 同步的数据导出,格式为.sql // */ // public function syncExportStr2File($fileName, $content){ // header_remove(); // ini_set('memory_limit', '128M'); // set_time_limit(1800); // header("Content-type:text/html;charset=utf-8"); // // header("Content-Transfer-Encoding: binary"); // // header("Content-Type: application/force-download;"); // header("Content-type: application/octet-stream"); // header("Cache-control: no-cache"); // header("Content-Transfer-Encoding: binary"); // header("Content-Disposition: attachment; filename=$fileName.sql"); // header("Expires: 0"); // header("Cache-control: private"); // header("Pragma: no-cache"); // header('Content-Length: ' . strlen($content)); // // $content = iconv('UTF-8', 'GBK//IGNORE', $content); // echo $content.PHP_EOL; // exit(); // } public function checkParams($input){ $input = json_decode($input,true); //json转数组 if(empty($input) || empty($input['list'])){ echo "参数不是JSON格式";exit(); } $input['count'] = intval($input['count']); $input['group_size'] = intval($input['group_size']); if( $input['count'] <= 0 || $input['group_size'] <= 0 || $input['count'] >= 5000 || $input['group_size'] >= 5000) { echo "条数、组数只能是 1 到 5000 以内";exit(); } } public function execute($input){ $this->checkParams($input); $input = json_decode($input,true); //json转数组 $inputList = $input['list']; //对于自增ID等忽略的类型,删除它并重排下标,不能用 array_splice ,删除多个时会乱 foreach ($inputList as $key => $item){ if($item['method'] == 'ignore'){ unset($inputList[$key]); } } $inputList = array_values($inputList); //从0开始 重建下标 $genCount = !empty($input['count']) ? $input['count'] : 5 ; $tableName = !empty($input['table_name']) ? $input['table_name'] : 'test'; $groupSize = $input['group_size']; //每个SQL有多少value组 $insertWay = !empty($input['insert_way']) ? $input['insert_way'] : 'INSERT INTO '; $keyArr = array_column($inputList,'key'); $generator = new ValueGenerator(); $sql = ''; //insert的SQL条数 for($genI = 1; $genI <= $genCount; $genI++) { $genResult = []; //生成结果数组: key => 生成方法+下标 防止同样的方法覆盖数据,value => 按该方法生成的数据数组 foreach ($inputList as $itemIndex => $item){ $genService = $this->camelize($item['method']); //方法名转驼峰 $genResult [ $item['method'].$itemIndex ] = $generator->$genService($item['value'],$groupSize,$genI ); } $valueStr = ''; //每个SQ有多少value组 for($cnt = 0; $cnt < $groupSize; $cnt++){ $valueStr .= '('; //取每个字段的值,单引号引起来 foreach ($genResult as $result) { $valueStr .= "'{$result[$cnt]}',"; } $valueStr = rtrim($valueStr,','); $valueStr .= '),'; } $valueStr = rtrim($valueStr,','); $valueStr .= ';'; $sql .= $insertWay . "{$tableName} (" . implode(",",$keyArr) .") VALUES $valueStr"; $sql .= "\n"; $sql .= "\n"; } //一直没成功,还怀疑是jq的post方法不是超链导致,最终用前端去做了 // $this->syncExportStr2File('datamake_'.date('YmdHis', time()).'sql' ,$sql); echo $sql; } /** * 下划线转驼峰 * @param $str * @param string $separator * @return string */ private function camelize($str,$separator='_') { $str = $separator. str_replace($separator, " ", strtolower($str)); return ltrim(str_replace(" ", "", ucwords($str)), $separator ); } } date_default_timezone_set("Asia/Shanghai"); $postData = file_get_contents('php://input'); //提交的是JSON,不能直接$post获取 if(empty($postData)){ echo "我是空白"; exit(); } //echo ($postData);exit(); $handler = new WorkHandler(); $handler->execute($postData); exit(); /* $parser = new CreateSqlParser(); $ret = $parser->execute($sql); if(0 == ($ret['error'])){ $input = json_encode($ret['data']); $handler = new WorkHandler(); $handler->execute($input); } else{ echo json_encode($ret);exit(); } */ ================================================ FILE: index.php ================================================ SQL测试数据生成
从 show create table tablename 获得




================================================ FILE: index_en.php ================================================ SQL Data Generator
show create table tablename




================================================ FILE: sqlparse.php ================================================ $matches[0][$cnt], 'key' => $matches[2][$cnt], 'type' => $matches[3][$cnt], 'others' => $matches[4][$cnt], ]; $ret []= $item; } return $ret; } /** * 解析字段名有 ` 包含的SQL,常见软件:Navicat * 正则匹配规则: 任意字符若干(空格或KEY) + `列名`+ 空格 + 非空字符串(类型) + 空格 + 额外信息 + 逗号或者),其中右括号结尾是表里没有任何索引的情况,支持跨行匹配 * 如果需要改动,需要注意: COMMENT 换行、 表无索引时最后个字段的情况,目前以 ` 来区分字段而非空格 * @param $sql CREATE TABLE `im_feed` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL DEFAULT '0', `user_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '学号或者老师工号', `content` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `is_deleted` tinyint(4) NOT NULL DEFAULT '0', `photos` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `create_time` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; * @return array 每个元素包含如下字段 * origin: 原SQL * key: 字段名 * type: 类型,包含可选的长度 int(11) 、text * others: 其他,NOT NULL AUTO_INCREMENT COMMENT '我是注释' 这种 */ private function parseWithBackQuote($sql){ //提前删除 INDEX 相关 INDEX cust_id (cust_id) USING BTREE, $sql = preg_replace("# *INDEX.+#","",$sql); $pattern = "#(.*)`(.+)` ([^\s]+) ([\s\S]+?)[,)]#im"; preg_match_all($pattern, $sql, $matches); // echo json_encode($matches);exit(); $ret = []; for ($cnt = 0; $cnt < count($matches[0]); $cnt++) { if (false !== stripos($matches[1][$cnt], 'KEY')) { //索引 排除 continue; } $item = [ 'origin' => $matches[0][$cnt], 'key' => $matches[2][$cnt], 'type' => $matches[3][$cnt], 'others' => $matches[4][$cnt], ]; $ret []= $item; } return $ret; } public function execute($input) { $sql = $input; $ret = []; //解析表名,兼容以下两种,返回的表名带不带 `都可以成功插入 // CREATE TABLE `test` ( // CREATE TABLE t_supplier_product // ( $sql = str_replace("IF NOT EXISTS","",$sql); $pattern = "#CREATE TABLE (.+?)[\s]#i"; preg_match($pattern, $sql, $matches); if (empty($matches)) { return $this->getApiReturn(self::errorParseError, '不是建表SQL,未包含 CREATE TABLE', []); } $ret['table_name'] = $matches[1]; //解析字段,推荐个在线正则网站 https://regexr.com/ $matchList = $this->parseWithBackQuote($sql); //带`的解析失败则用不带`的解析,大部分SQL是带`的 if (empty($matchList)) { $matchList = $this->parseWithoutBackQuote($sql); } $ret['list'] = []; if (empty($matchList)) { return $this->getApiReturn(self::errorParseError, '未查找到SQL字段', []); } // echo json_encode($matchList); exit(); // 解析后拿到的每个item: // "origin":" `baoguang_pv` int(11) NOT NULL DEFAULT '0' COMMENT '昨日曝光pv',", // "key":"baoguang_pv", ======= 字段名 // "type":"bigint(20)", ======= 类型,包含可选的长度 int(11) 、text // "others":"NOT NULL DEFAULT '0' COMMENT '昨日曝光pv'" ======= 其他,NOT NULL AUTO_INCREMENT COMMENT '我是注释' 这种 foreach ($matchList as $item){ $size = 0; $type = $item['type']; $sizeArr = explode('(',$item['type']); //如果有()说明是有数字的那种 if(!empty($sizeArr) && count($sizeArr) >= 2 ) { $type = $sizeArr[0]; $size = explode( ")" ,$sizeArr[1] )[0] ; } $entry = $this->genDefaultAttribute($item['key'], $type , $size, $item['others']); $entry['key'] = $item['key']; $ret['list'] [] = $entry; } $ret['group_size'] = 5; //组大小 $ret['count'] = 3; //多少条SQL return $this->getApiReturn(0, '', $ret); } /** * @param $key * @param $type string SQL的字段类型 varchar,int * @param $size string SQL的字段类型后跟随的大小 如 varchar(10) 中的10 * @param $others string varchar(10) 后面的一串其他完整内容,包含 自增、非空、默认值等 * @return array item 必备包含 'key' 字段名 'method' 生成规则 'value' 默认值 */ private function genDefaultAttribute($key, $type, $size, $others) { $type = strtolower(trim($type)); $incrStrPre = ['Boss', 'Player', 'Test', 'PM', 'Programmer', 'Worker', 'Actor', 'SB']; switch ($type) { case 'varchar': $item = [ 'desc' => '前缀+自增', 'method' => self::INCR_STR_PREFIX, 'value' => $incrStrPre[rand(0, count($incrStrPre) - 1)], ]; break; case 'int': case 'mediumint': case 'integer': $item = [ 'desc' => '随机整数', 'method' => self::RAND_INT, 'value' => '100,500', ]; break; case 'bigint': $item = [ 'desc' => '随机整数', 'method' => self::RAND_INT, 'value' => "1000000,99999999", ]; break; case 'tinyint': $item = [ 'desc' => '随机整数', 'method' => self::RAND_INT, 'value' => "0,{$size}", //tinyint(4) 一般是0-4的枚举值 ]; break; case 'float': case 'double': $item = [ 'desc' => '随机浮点', 'method' => self::RAND_FLOAT, 'value' => '1,10,5', ]; break; case 'date': //这个待定 case 'datetime': case 'timestamp': $item = [ 'method' => self::RAND_TIMESTAMP_MYSQL, 'value' => '20180407,20180408', ]; break; case 'text': default: $item = [ 'method' => self::CONST_STR, 'value' => '1', ]; break; } //自增ID $autoInc = stripos($others, "AUTO_INCREMENT"); if ($autoInc !== false) { $item = [ 'method' => self::IGNORE, 'desc' => '自增ID,忽略', ]; } //注释 $expComment = explode("COMMENT ", $others); if (!empty($expComment) && count($expComment) >= 2 ) { $item['comment'] = trim($expComment[1], "',"); } //通用配置 $commonItem = $this->parseFileForAttribute('conf/common.ini',$key); if(!empty($commonItem)){ $item = $commonItem; } //个性化配置 //针对你、你公司 常用的字段设置默认值,存放不可告人的数据秘密,配置文件在.gitignore里 $localItem = $this->parseFileForAttribute('conf/local.ini',$key); if(!empty($localItem)){ $item = $localItem; } return $item; } /** * 解析ini文件拿到自定义默认值,根据字段名猜测用户想要的是哪个类型,配置文件样例如下,目前只支持 模糊查找 和 精确匹配 [0] key = avatar method = RAND_PIC_URL value = 300,400 way = search 跟key的匹配方式,search为模糊搜索,输入key包含 avatar 就走这个匹配 [1] key = index_day method = INCR_DAY value = 20180301 way = match match为精确匹配,输入key 等于 index_day 就走这个匹配 * * * @param $fileName string 配置文件路径 * @param $key string 字段名 * @return array */ private function parseFileForAttribute($fileName,$key) { if(!file_exists($fileName)){ return []; } $item = []; $matchArray = parse_ini_file($fileName,true); foreach ($matchArray as $match) { if(empty($match['way'])){ //默认key规则为相等 $match['way'] = 'match'; } if($match['way'] == 'search' && false !== stripos($key, $match['key'])){ $item = $match; $item['method'] = strtolower($item['method']); }else if ($match['way'] == 'match' && $key == $match['key']) { $item = $match; $item['method'] = strtolower($item['method']); } } unset($item['way']); return $item; } } date_default_timezone_set("Asia/Shanghai"); $defaultSql = " CREATE TABLE `im_feed` ( `id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL DEFAULT '0', `user_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '学号或者老师工号', `content` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `is_deleted` tinyint(4) NOT NULL DEFAULT '0', `photos` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `create_time` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; "; $defaultSql2 = " CREATE TABLE t_supplier_product ( id INT AUTO_INCREMENT PRIMARY KEY, supplier_id INT NOT NULL COMMENT '供应商id', product_detail_id INT NOT NULL COMMENT '单品id', price DOUBLE NOT NULL COMMENT '采购价', KEY (`supplier_id`) ) COMMENT '供应商货品' ENGINE = InnoDB CHARSET = utf8; "; $parser = new CreateSqlParser(); if(empty($_POST['sql'])){ $sql = $defaultSql; }else{ $sql = $_POST['sql']; } $ret = $parser->execute($sql); echo json_encode($ret);exit();