Prevent duplicates in database

前端 未结 4 1693
有刺的猬
有刺的猬 2021-01-25 16:45
$db->query(\"SELECT * FROM \".DB_PREFIX.\"users WHERE uid=\'\".$uid_id.\"\' AND login=\'ExpressCheckoutUser\'\");
                if ($db->moveNext())
                     


        
4条回答
  •  一个人的身影
    2021-01-25 17:07

    First and last name are nice, but everything but unique. I know a few people that have the same name I do, so I guess building a unique index on those two columns will only frustrate, not help. The thing that makes me unique though is that I am the only one who has both my e-mail address and password, so I think that would be a better candidate.

    ALTER TABLE users ADD UNIQUE unique_emailaddress ( email );
    

    That should at least help with some of the duplicates, but not all: users may have multiple e-mail addresses (I know I do ;)), but it still better than an arbitrary combination of first and last name which isn't unique at all.

提交回复
热议问题