members_location 表與 members 表是一對一關係,該錶只負責儲存歸屬地資訊
drop table if exists `members_location`;當某些使用者符合條件需要查詢歸屬地是,只要將其插入到 members_mobile 表即可。該錶使用黑洞引擎並不會儲存手機號碼,所以明文手機號碼安全得到了保障。create table if not exists `members_location` (
`id` int(10) unsigned not null,
`province` varchar(50) not null,
`city` varchar(50) not null,
`ctime` timestamp not null default current_timestamp,
primary key (`id`),
key `province` (`province`),
key `city` (`city`),
constraint `fk_members_location_members` foreign key (`id`) references `members` (`id`)
) engine=innodb default charset=utf8;
drop table if exists `members_mobile`;當有資料進入到 members_mobile 時出發器 members_mobile_insert 會工作,去 mobile_location 表中查詢歸屬地後儲存在 members_location 表中create table if not exists `members_mobile` (
`id` int(10) not null,
`number` varchar(11) not null
) engine=blackhole default charset=utf8;
drop trigger if exists `members_mobile_insert`;mobile_location 是儲存手機號段與歸屬地資訊的資料庫set @oldtmp_sql_mode=@@sql_mode, sql_mode='';
delimiter //
create trigger `members_mobile_insert` before insert on `members_mobile` for each row begin
insert into members_location(id,province,city) select new.id,mobile_location.province,mobile_location.city from mobile_location where mobile_location.id = md5(left(new.number, 7));
end//
delimiter ;
set sql_mode=@oldtmp_sql_mode;
drop table if exists `mobile_location`;create table if not exists `mobile_location` (
`id` varchar(50) not null,
`province` varchar(50) default null,
`city` varchar(50) default null,
primary key (`id`)
) engine=innodb default charset=utf8;
第五節 8 手機歸屬地查詢案例
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
第五節 8 手機歸屬地查詢案例
using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...
身份證號歸屬地資料庫
drop function ifexists f base check id number create function f base check id number number varchar 18 charset utf8 returns int 原理 第一代身份證十五位數公升為第二代身份證...