Mysql database generally uses ID or user name for association
三叔
三叔 2017-06-24 09:41:31
0
7
1617

I am a front-end person, and I am exploring while working on a personal php project. I need to pass a user ID through a connection to display the data of the corresponding user. I am using mysql.

<a href="./index.php?ui=<?php echo $_SESSION[ 'username' ] ?>">

So I would like to ask whether id or username is generally used for this identification (association). If username is used for association, it can be obtained from the session.
Do you have to pass the ID to the front when using id association?

三叔
三叔

reply all(7)
滿天的星座

If username is unique, I personally recommend using username.
ID is usually self-increasing, so you can roughly estimate the real number of users of the website based on the ID.
For example: Many websites like to "show off" with the number of registered users, claiming to have how many registered users they have (more than 90% of them are bragging), so the ID must not be exposed.
Of course, if the ID you define is irregular, or you don’t need to hide this information externally, ID is perfect.

巴扎黑

Id. What if the username becomes the same? So id must be set as the primary key

伊谢尔伦

1. Usually id is used
2. Most of the id is not the primary key identifier, but the user's unique code
3. It seems that you are not very good at background language. Since you use session as a parameter, you can directly have background processing. Rather than using front-end processing. So there is no need to pass the ID

学霸

There are no hard requirements, but if you want to consider performance, just choose something short and simple.

For example:
Optimize performance and reduce matching processes such as numerical matching and string matching

给我你的怀抱

This depends on your database design, but generally it is done with ID, username is not safe

阿神

We use sn, the user’s unique serial number

Ty80

Understand the primary keys and foreign keys of the database

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template