建立表:
CREATE TABLE IF NOT EXISTS `postdata` ( `id` int(11) NOT NULL auto_increment, `city` varchar(255), `time` varchar(255), `code` varchar(255), `school` varchar(255), `pay` varchar(255), `state` varchar(255), `updatetime` datetime PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
插入数据:
INSERT INTO `condition` VALUES (1, 'Beijing', '2012-11-16 17:06:02');
INSERT INTO `condition` VALUES (2, 'Hebei', '2012-11-16 17:07:02');
INSERT INTO `condition` VALUES (3, 'Shanxi', '2012-11-16 17:08:02');
INSERT INTO `condition` VALUES (4, 'Tianjin', '2012-11-16 17:09:02');
INSERT INTO `condition` VALUES (5, 'Anhui', '2012-11-16 17:10:02');
INSERT INTO `condition` VALUES (6, 'Fujian', '2012-11-16 17:11:02');
INSERT INTO `condition` VALUES (7, 'Jiangsu', '2012-11-16 17:12:02');
INSERT INTO `condition` VALUES (8, 'Jiangxi', '2012-11-16 17:13:02');
INSERT INTO `condition` VALUES (9, 'Shandong', '2012-11-16 17:14:02');
INSERT INTO `condition` VALUES (10, 'Shanghai', '2012-11-16 17:15:02');
INSERT INTO `condition` VALUES (11, 'Zhejiang', '2012-11-16 17:16:02');
INSERT INTO `condition` VALUES (12, 'Guangdong', '2012-11-16 17:17:02');
INSERT INTO `condition` VALUES (13, 'Guangxi', '2012-11-16 17:18:02');
INSERT INTO `condition` VALUES (14, 'Guizhou', '2012-11-16 17:19:02');
INSERT INTO `condition` VALUES (15, 'Hainan', '2012-11-16 17:20:02');
INSERT INTO `condition` VALUES (16, 'Henan', '2012-11-16 17:21:02');
INSERT INTO `condition` VALUES (17, 'Hubei', '2012-11-16 17:22:02');
INSERT INTO `condition` VALUES (18, 'Hunan', '2012-11-16 17:23:02');
INSERT INTO `condition` VALUES (19, 'Heilongjiang', '2012-11-16 17:24:02');
INSERT INTO `condition` VALUES (20, 'Jilin', '2012-11-16 17:25:02');
INSERT INTO `condition` VALUES (21, 'Liaoning', '2012-11-16 17:26:02');
INSERT INTO `condition` VALUES (22, 'Gansu', '2012-11-16 17:27:02');
INSERT INTO `condition` VALUES (23, 'Inner Mongolia', '2012-11-16 17:28:02');
INSERT INTO `condition` VALUES (24, 'Ningxia', '2012-11-16 17:29:02');
INSERT INTO `condition` VALUES (25, 'Qinghai', '2012-11-16 17:30:02');
INSERT INTO `condition` VALUES (26, 'Shaanxi', '2012-11-16 17:31:02');
INSERT INTO `condition` VALUES (27, 'Xinjiang', '2012-11-16 17:32:02');
INSERT INTO `condition` VALUES (28, 'Chongqing', '2012-11-16 17:33:02');
INSERT INTO `condition` VALUES (29, 'Sichuan', '2012-11-16 17:34:02');
INSERT INTO `condition` VALUES (30, 'Tibet', '2012-11-16 17:35:02');
INSERT INTO `condition` VALUES (31, 'Yunnan', '2012-11-16 17:36:02');
修改主键:
Alter table `postdata` change `id` `id` int(10) default 0 not null auto_increment=1;
假设发现主键设置错了,应该是id是主键,但现在表里已经有好多数据了,不能删除表再重建了,只能在这基础上修改表结构。
先删除主键 alter table table_test drop primary key;
然后再添加主键 alter table table_test add primary key(id);
php获取当前时间:
date('y-m-d H:i:s',time());
mysql获取当前时间:
now();
php没有now()这个函数,应该是time();