03.11.2018, 10:01
Quote:
Hey, thanks a lot for the tips, I really appreciate it, I've done everything you mentioned, (Commit) except the datetime, do you have an example or something? And I want to keep the same actual form displayed in the dialogs, if possible.
|
pawn Code:
SELECT IP,
DATE_FORMAT(Connected, '%%Y %%M %%e - %%T') AS Connected
FROM iplogger
WHERE Name = '%e'
When your table does not have a primary key and searches by name, it filters about 10 percent -- it scans the whole table for looking any matches. A name cannot be unique as a player can connect more than once but a pair can be. A player joins a specific time, this pair is unique and we can also take advantage of it.
pawn Code:
CREATE TABLE `iplogger` (
`Name` varchar(24) NOT NULL,
`IP` varchar(15) NOT NULL,
`Connected` datetime NOT NULL,
`Disconnected` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`Name`,`Connected`)
)
Store unix timestamp on connect for a player and use FROM_UNIXTIME when a player disconnects.
pawn Code:
INSERT INTO iplogger (Name, IP, Connected)
VALUES ('%s', '%s', FROM_UNIXTIME(%d))
https://dev.mysql.com/doc/refman/8.0...tion_inet-aton
https://dev.mysql.com/doc/refman/8.0...tion_inet-ntoa
Store IP as unsigned int and the use is very simply INET_ATON('127.0.0.1') and INET_NTOA(IP)