我想启动一个大项目,其中users
表将有很多行。
Users table structure is this: id|username|password|email id - auto_increment + primary_key username - unique index email - unique index
我希望我的用户能够使用用户名或电子邮件登录,但如果这会减慢我的查询速度,我将仅使用一个输入。
我。 (用户名或电子邮件登录) 我为此执行 stmt:
$post_input = $_POST['user_input'] //will be username or email
$check = $db->prepare("Select * from users where username=? or email=?")
$check->execute(array($post_input,$post_input));
if($check->rowCount() > 0){
//Username or Email found from here do the rest of the things
}
二. (仅用户名登录) 我为此执行 stmt:
$post_input = $_POST['user_input'] //will be username
$check = $db->prepare("Select * from users where username=?")
$check->execute(array($post_input));
if($check->rowCount() > 0){
//Username found from here do the rest of the things
}
当用户表达到大约 100 万用户时,哪一个查询会执行得更好更快。
最佳答案
一种选择是让您的应用程序检查用户输入中的@,如果存在则检查电子邮件,如果不检查用户名(当然,如果@在用户名中可以接受,则可能会导致问题)
关于php - 大型数据库最快的登录检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21888444/