mysql转sqlite

2020-1-15 19:32:57 星期三

1. 建表语句

 1 $createTable = " CREATE TABLE `user` (
 2   `uid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id',
 3   `addtime` int(11) unsigned DEFAULT '0' COMMENT '添加时间戳',
 4   `status` tinyint(4) NOT NULL DEFAULT '0',
 5   `username` varchar(20) NOT NULL DEFAULT '' COMMENT '用户名',
 6   `mobile` varchar(11) NOT NULL DEFAULT '' COMMENT '手机号',
 7   `email` varchar(50) NOT NULL DEFAULT '',
 8   `password` varchar(64) NOT NULL DEFAULT '' COMMENT '密码',
 9   `reg_from` varchar(20) NOT NULL DEFAULT '' COMMENT '注册来源',
10   `unid` char(32) NOT NULL DEFAULT '',
11   `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
12   PRIMARY KEY (`uid`),
13   KEY `username` (`username`)
14 ) ENGINE=InnoDB AUTO_INCREMENT=262 DEFAULT CHARSET=utf8;";
15 
16 
17 $createTable = str_replace('`', '', $createTable);
18 $createTable = preg_replace('/COMMENT.*,/U', ',', $createTable);
19 $createTable = preg_replace("/\'(\d+)\'/U", '$1', $createTable);
20 $createTable = preg_replace("/AUTO_INCREMENT=\d+/", '', $createTable);
21 $createTable = preg_replace("/KEY\s+[a-z0-9]+\s\(.*\)/i", '', $createTable);
22 $createTable = preg_replace("/(PRIMARY\sKEY\s\(.*\)),/i", '$1', $createTable);
23 $createTable = str_replace(['unsigned', 'ENGINE=InnoDB', 'DEFAULT CHARSET=utf8', 'AUTO_INCREMENT'], [''], $createTable);
24 
25 
26 echo $createTable;
27 echo '<pre>';
28 echo $createTable;

 

posted @ 2020-01-15 19:42  myD  阅读(896)  评论(0编辑  收藏  举报