Wechat users and mobile phone number users are in two tables, how to bind each other

deal with the problem that Wechat users bind mobile numbers and mobile phone numbers bind Wechat

now the tricky thing is that Wechat users and mobile phone number users are in two tables.
what"s more tricky is that Wechat users and mobile phone number users both have related data. How to do this if they are bound.

also, if you want to combine these two tables into one table, do you have any ideas, gods, ask for advice, thank you

Mar.24,2021

you can think of Wechat users and mobile phone number users as two login methods.
I recommend not composing a table.
this is my user table minimalist design

< H1 > member < / H1 >
CREATE TABLE `member` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tel` bigint(20) DEFAULT NULL COMMENT '',
  `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' 0:',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `member_tel_unique` (`tel`),
  KEY `member_tel_status_index` (`tel`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
< H1 > member_data < / H1 >
CREATE TABLE `member_data` (
  `member_id` bigint(20) NOT NULL COMMENT '',
  `sex` enum('0','1','2') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT ' 0=> 1=> 2=>',
  `nick_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '/',
  `img` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  UNIQUE KEY `member_data_member_id_unique` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
< H1 > member_authorized < / H1 >
CREATE TABLE `member_authorized` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` bigint(20) NOT NULL COMMENT '',
  `prefix` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `data` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `member_authorized_prefix_index` (`prefix`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

if Wechat users have an independent user id, it will be difficult to organize. It can only be regarded as two users. If you merge two users into one, I feel I can write a function. To prompt the user whether to merge the two, let the user choose


when binding a mobile phone, save the record of the mobile phone user to the Wechat user table. In other words, add a field to the Wechat user table to associate with the mobile phone user table.


suggest a final primary table. Wechat has a user id field in a table, and the user's id in the primary table is self-increasing primary key


two tables are done.

  1. user table

attribute: user's ID, nickname, avatar, and other user attributes, not mobile phone number

  1. Login method Table

attribute: primary key ID,type (mobile or Wechat openid and other types of), openid (mobile numbers or other types of id,varchar used by Wechat openid and other types of id,varchar (40)), user ID,banned (whether login is prohibited)

type+openid do an index.
if you bind, you can insert a piece of data into the table without confusion.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37fd5-2c107.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37fd5-2c107.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?