The PK column need to be of a numerical type (like 'int' if you are ambitious enough to expect more then 16.7 miljon users. If you expect less account, then you can use a 'mediumint' or 'smallint' (<-- max value = 65 535)
An examplesntax
CREATE TABLE `usertable` (
`userID` INT (8) UNSIGNED DEFAULT '0' AUTO_INCREMENT,
`uname` VARCHAR (25) NOT NULL,
`upwd` VARCHAR (35) NOT NULL,
`nick` VARCHAR (35) DEFAULT 'user',
PRIMARY KEY(`userID`), UNIQUE(`uname`),
INDEX(`userID`,`uname`,`upwd`))
COMMENT = "The table with your applications useraccounts"
Quote:
|
Now if you wanna referr to their username don't u still have to refer to it in the script? You can't just refer to the primary key as there could be multiple values in that record.
|
If you need user data like the username or the nickname they choose (much better to seperate the two), then you run a select for it. There is no point to store all data that you could need somewhere in your app inside a sessionvariable. If you have the PK of the usertable, then you can quickly lookup the userdata. Like
$sql="select nick from usertable where userID=" . $_SESSION['uid'] ;
don't be afraid to run selects on your db. Such simple ones like this one have about no impact at all on your responsetimes or db-load.