[REP ++] Mysql data is mixing sometimes
#1

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.
Reply
#2

Show how you are setting szPlayerName.
Reply
#3

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

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

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?
Reply
#6

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.
Reply
#7

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 ?
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)