php - 大型数据库最快的登录检查

标签 php mysql

我想启动一个大项目,其中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/

相关文章:

python - 我的程序没有更改 MySQL 数据库,但也没有出现错误

php - sql - 在没有额外查询的情况下更新时检查行是否存在?

php - 处理商店开门和关门时间

php - Magento 继承链。好的还是坏的做法?

php - 在php中按日期降序排列数组

mysql - 在MySql中,是否值得在同一组列上创建多个多列索引?

php - 使用 PHP5 哈希功能时遇到的问题

php - sql查询显示2个日期之间的所有行

php - SQL:获取 null 作为与查询不匹配的行的返回值

php - 在 laravel 5.1 中更改请求默认数据库