Reputation: 410
user id or username which is better to save in session and also in mysql which is the best way.
--> "select * from usertable where loginname=" . $_SESSION['username'];
or
--> "select * from usertable where id=" . $_SESSION['id'];
whether integer comparison or string comparison which is the best comparison in SQL.
Upvotes: 0
Views: 1027
Reputation: 44444
What you are thinking doesnt really make much sense to me, really!
Integer comparison or String comparison -- Why do you think one will be faster that the other? Of course, if you go instruction by instruction Integer comparison will be faster, but why do you want that?
My answer: Stick to what ever you want. Choose the one that will be guaranteed to be unique. Plus, choosing username, isnt something great. Generate a unique ID for every user that is logged on. And store that ID into the $_SESSION[..]
. Obviously, you would need to have some mechanism to validate the ID, and associate it with the username.
Upvotes: 1
Reputation: 61737
You should usually save the ID, because if you are running a fully normalised database this is the value that is most useful to you when performing other lookups.
Upvotes: 4
Reputation: 834
Integers comparison is always more accurate than strings, also you would like to consider the fact, the id is unique for each user, and there maybe an several user with the same username, that depends on your system.
I believe id comparison is the best way to go
Upvotes: 0