系统允许手机和邮箱注册,如何保证唯一性
如果只有手机注册,只要给手机做唯一索引即可,但是如果邮箱也可以注册,那进来的就不一定是手机了,也就是说mobile和email两个都不能设唯一索引,因为如果两个手机用户注册进来了,就会有两个email为空的记录,存在不唯一的情况,反之亦然。怎么处理?
回复内容:
如果只有手机注册,只要给手机做唯一索引即可,但是如果邮箱也可以注册,那进来的就不一定是手机了,也就是说mobile和email两个都不能设唯一索引,因为如果两个手机用户注册进来了,就会有两个email为空的记录,存在不唯一的情况,反之亦然。怎么处理?
我感觉有两种解决方案:
1、email和mobile设为同一个字段。
2、email和mobile同时设为unique,但是允许null,当同为null时是可以插入成功的
手机+邮箱做唯一索引呢
楼上两个字段同时判断应该可行。
但一定要用这两个字段作唯一索引吗?另增一个字段,添加记录时添入唯一索引值不知可以不?
你把手机和邮箱设置为联合唯一索引。
UNIQUE INDEX table
('mobilePhone','email)
这个很简单呀,选择邮箱注册则邮箱是唯一标识(用于登录),可以绑定多个手机。如果是手机注册,手机是唯一标识,理论上也可以绑定多个邮箱(但实际大多数禁止多个)。这种状态就可以通过手机和邮箱注册两个互不影响登录的账号。所以唯一性是必须的,但是不同类型的账号是可以存在你所谓的不唯一!好好理解下吧!
可以使用一个无意义的唯一数作为用户的索引,然后注册时判断使用的手机或邮箱是否已经注册过。如果没有注册过就生成一个新的唯一数作为这个新注册用户的索引。
邮箱和手机的唯一性通过注册时的判断来保证。
但是日后如果用户补充注册时未填写的手机或邮箱时,就需要考虑是否仍要保证唯一性了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
