一、select
- 一般形式(表名、以这个字段为分表、查找指定条件的记录、可选条件空、返回当前满足的所有记录)
game_db_data:select(
player_effect,
1000000379,
[{
#player_effect{
player_id = 1000000379,
_ = '_'
},
[],
['$_']
}]
).
- 条件放在第四个参数
game_db_data:select(
player_effect,
1000000379,
[{
#player_effect{
player_id = '$1',
_='_'
},
[{'<','$1',1000000379}, , 。。。。],
['$_']
}]
).
- 返回指定的多个字段而不是满足条件的所有记录
game_db_data:select(
player_effect,
1000000379,
[{
#player_effect{
player_id = '$1',
effect_id = '$2',
effect_id = '$2',
_='_'
},
[{'=<','$1',1000000379}],
[{{'$1','$2'}}]
}]
).
- 返回指定的单个字段而不是满足条件的所有记录
game_db_data:select(
// 表名
player_effect,
// 分表id
1000000379,
// 匹配matchspec
[{
#player_effect{
player_id = '$1',
effect_id = '$2',
_='_'
},
[{'=<','$1',1000000379}], 且就多个元组条件,或者的话就如下所示
[
{
'orelse',
{'==','$1', 0},
{'>', '$1', NowTime}
}
],
['$1']
}]
).
二、write、read、delete
%%-----只要填好主键,就可以写入/更新
game_db_data:write(#player_first_charge{player_id = 1000000001,status = ?ST_HAVE_GET}),写入一条新纪录
game_db_data:read(#pk_player_first_charge{player_id = PlayerId})
game_db_data:delete((PlayerFirstCharge)找出来,然后把这个记录删除
三、数据库建表模板
<?php
execute("
ALTER TABLE `test_player_token` ADD COLUMN `nickname` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '昵称' AFTER `srv_id`;
ALTER TABLE `test_player` ADD COLUMN `is_male` TINYINT NOT NULL DEFAULT 1 COMMENT '是否男性' AFTER `nickname`;
DROP TABLE IF EXISTS `robot`;
CREATE TABLE `robot` (
`id` INTEGER NOT NULL AUTO_INCREMENT COMMENT 'id',
`nickname` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '昵称',
`zhi_hui_bu_level` INTEGER NOT NULL DEFAULT 0 COMMENT '指挥部等级',
`player_level` INTEGER NOT NULL DEFAULT 0 COMMENT '玩家等级',
`vip_level` INTEGER NOT NULL DEFAULT 0 COMMENT 'vip等级',
`crops` VARCHAR(128) NOT NULL DEFAULT '' COMMENT '兵种',
`resource` VARCHAR(128) NOT NULL DEFAULT '' COMMENT '资源',
PRIMARY KEY (`id`),
KEY `time` (`time`) USING BTREE,
KEY `player_id` (`player_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='机器人';
");
?>
text 没有default
修改字段类型 用modify