SA-MP Forums Archive
[REP ++] Mysql data is mixing sometimes - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [REP ++] Mysql data is mixing sometimes (/showthread.php?tid=587862)



[REP ++] Mysql data is mixing sometimes - buburuzu19 - 03.09.2015

I recently had some problems with my mysql database , sometimes mysql data of a player goes to another player and so on. It's like a mixture between datas.

How i load player accounts:
pawn Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `playerName` = '%s' LIMIT 1", szPlayerName);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
pawn Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{

    playerVariables[playerid][pLanguage] = cache_get_field_content_int(0, "playerLanguage");
    playerVariables[playerid][pSex] = cache_get_field_content_int(0, "playerSex");
        and so on...
}
Please remember that the problem is happening just sometimes.
What should i check ? What problem could be? Thanks for your support. I will rep you soon.


Re: [REP ++] Mysql data is mixing sometimes - ThePhenix - 03.09.2015

Show how you are setting szPlayerName.


AW: [REP ++] Mysql data is mixing sometimes - Macronix - 03.09.2015

Are you resetting the variables after you save everything ? (e.g. in OnPlayerDisconnect)


Re: [REP ++] Mysql data is mixing sometimes - buburuzu19 - 03.09.2015

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
Show how you are setting szPlayerName.
new szPlayerName[MAX_PLAYER_NAME];


Re: AW: [REP ++] Mysql data is mixing sometimes - buburuzu19 - 03.09.2015

Quote:
Originally Posted by Macronix
Посмотреть сообщение
Are you resetting the variables after you save everything ? (e.g. in OnPlayerDisconnect)
I am reseting variables at OnPlayerConnect, then load new ones.

I do it like this under OnPlayerConnect:

playerVariables[playerid][pSex] = 0;
playerVariables[playerid][pLevel] = 1;

Any new answers?


Re: [REP ++] Mysql data is mixing sometimes - Vince - 03.09.2015

You should be checking if there are rows. I'm not sure about this, but perhaps an older cache is being loaded if it isn't replaced with a new one (due to there being no rows in the resultset).

I also want to highlight two petpeeves of mine: the first is using the name as the key. This is fine the first time around but for every other query you should use the primary key. The second is using "sz". Systems Hungarian is a dumb and redundant system. You don't have to be a genius to figure out that a name is a string.


Re: [REP ++] Mysql data is mixing sometimes - buburuzu19 - 03.09.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
You should be checking if there are rows. I'm not sure about this, but perhaps an older cache is being loaded if it isn't replaced with a new one (due to there being no rows in the resultset).
I am checking if the account exists, if he exists it will send player to login, if not to register.

Like this:

pawn Код:
mysql_format(mysql, query, sizeof(query),"SELECT `playerPassword`, `playerCode`, `playerBanned`, `playerID` FROM `accounts` WHERE `playerName` = '%s' LIMIT 1", szPlayerName);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows > 0)
    {
        cache_get_field_content(0, "playerPassword", playerVariables[playerid][pPassword], mysql, 129);

        playerVariables[playerid][pInternalID] = cache_get_field_content_int(0, "playerID");
       
    }
    else
    {
      Send player to register and so on..
    }




}
And after player logs in it will execute OnAccountLoad.

Is that what are you trying to say ?


Re: [REP ++] Mysql data is mixing sometimes - buburuzu19 - 03.09.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
I also want to highlight two petpeeves of mine: the first is using the name as the key. This is fine the first time around but for every other query you should use the primary key. The second is using "sz". Systems Hungarian is a dumb and redundant system. You don't have to be a genius to figure out that a name is a string.
Can you give me an example , i didn't understand very good what you've tried to say.