View Single Post
jonatat
Senior Member
Join Date: Dec 2017
Old 06-01-2018 , 04:14   Re: Save player data to mysql
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
You can also use REPLACE INTO if your table is created properly.

Code:
REPLACE works exactly like INSERT , except that if an old row in the table has 
the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is 
deleted before the new row is inserted. See Section 12.2.5, “ INSERT Syntax”. 
REPLACE is a MySQL extension to the SQL standard.
You can make the steam ID your primary key since this value is static.
Code:
CREATE TABLE IF NOT EXISTS tblPlayerData (SteamID VARCHAR(34) PRIMARY KEY , PlayerName VARCHAR(32), PlayTime INTEGER);

REPLACE INTO tblPlayerData (SteamID, PlayerName, PlayTime) VALUES ('STEAM123','bugsy',1);
You really helped me with PRIMARY_KEY!

Does it okay?

Code:
formatex( szQuery, 3799, "UPDATE `users` SET `steam_id` = '%s', `player_name` = '%s', `kills` = '%d', `deaths` = '%d', `headshots` = '%d', `aces` = '%d', `m_aces` = '%d', `mix_played` = '%d', `mix_lost` = '%d', `mix_won` = '%d', `mix_draw` = '%d', `points` = '%d' WHERE `steam_id` = '%s';", steam, GetSecureName(Name), pKills[id], pDeaths[id], pHeadshots[id], pAces[id], pMiniAces[id], pMixPlayed[id], pMixLost[id], pMixWon[id], pMixDraw[id], pPoints[id], steam);

Last edited by jonatat; 06-01-2018 at 04:16.
jonatat is offline