mysql not loading
#1

Can someone explain me why this mysql isn't loading player's stats after login?

pawn Код:
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysqlc);
    if(rows)
    {
        cache_get_field_content(0, "password", PlayerInfo[playerid][Password], mysqlc, 129);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login in your account", ""W"In order to play, you need to "R"login", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Create a new account", ""W"In order to play, you need to "R"register.", "Register", "Quit");
    }
    return 1;
}
This is the public that executes after login:

pawn Код:
public OnAccountLoad(playerid)
{
    PlayerInfo[playerid][Admin] = cache_get_row_int(0, 5);
    PlayerInfo[playerid][Deaths] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][Nopm] = cache_get_row_int(0, 7);
    PlayerInfo[playerid][Muted] = cache_get_row_int(0, 8);
    PlayerInfo[playerid][Vip] = cache_get_row_int(0, 9);
    PlayerInfo[playerid][Warn] = cache_get_row_int(0, 10);
    PlayerInfo[playerid][RegisterDate] = cache_get_row_int(0, 11);
    PlayerInfo[playerid][Jailed] = cache_get_row_int(0, 12);
    PlayerInfo[playerid][AdminActions] = cache_get_row_int(0, 13);
    PlayerInfo[playerid][Cookies] = cache_get_row_int(0, 14);
    PlayerInfo[playerid][Rank] = cache_get_row_int(0, 15);
    PlayerInfo[playerid][VipTime] = cache_get_row_int(0, 16);
    PlayerInfo[playerid][Class] = cache_get_row_int(0, 17);
    PlayerInfo[playerid][PrototypesStolen] = cache_get_row_int(0, 18);
    PlayerInfo[playerid][KillAsUsaTeam] = cache_get_row_int(0, 19);
    PlayerInfo[playerid][KillAsGermanyTeam] = cache_get_row_int(0, 20);
    PlayerInfo[playerid][KillAsItalyTeam] = cache_get_row_int(0, 21);
    PlayerInfo[playerid][KillAsJapanTeam] = cache_get_row_int(0, 22);
    PlayerInfo[playerid][KillAsMercTeam] = cache_get_row_int(0, 23);
    PlayerInfo[playerid][KillAsMexicoTeam] = cache_get_row_int(0, 24);
    PlayerInfo[playerid][Exp] = cache_get_row_int(0, 26);
    PlayerInfo[playerid][Duty] = cache_get_row_int(0, 27);
    PlayerInfo[playerid][DaysAlive] = cache_get_row_int(0, 28);
   
    SetPlayerScore(playerid, PlayerInfo[playerid][Scores]);
    GivePlayerMoney(playerid, PlayerInfo[playerid][Cash]);
    JustLogged[playerid] = 1;
    Logged[playerid] = 1;
    UpdateStatsTextdraw(playerid);
    SendClientMessage(playerid,red,"------------------------------------------------------");
    new playername3[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername3, sizeof(playername3));
    new string[128];
    format(string,sizeof(string),"* System: Welcome back {F70505}%s (%d) {FFFFFF} - Your stats have been restored.",playername3,playerid);
    SCM(playerid,-1,string);
    SendClientMessage(playerid,red,"------------------------------------------------------");
    CheckVipTime(playerid);
    return 1;
}
Dialog login:

pawn Код:
if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
        SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
        KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
        }
        if(response)
        {
            new hpass[129];
            WP_Hash(hpass, 129, inputtext);
            new name[24];
            GetPlayerName(playerid, name, sizeof(name));
            printf("Hpass: %s Password: %s", hpass, PlayerInfo[playerid][Password]);
            if(!strcmp(hpass, PlayerInfo[playerid][Password]))
            {
                mysql_format(mysqlc, query, sizeof(query), "SELECT * FROM `playerdata` WHERE `user` = '%e' LIMIT 1", name);
                mysql_tquery(mysqlc, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login in your account", ""W"In order to play, you need to "R"login\n"R"Wrong password!", "Login", "Quit");
            }
        }
    }
Screen of the database:

http://oi41.tinypic.com/23w193s.jpg

As you can see, im loading from the the "Admin" field, which is at number 5. Then other stats.

Whats wrong?

Log:

Quote:

[13:56:48] [DEBUG] Calling callback "OnAccountLoad"..
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 5, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '5', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 6, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '6', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 7, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '7', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 8, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '8', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 9, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '9', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 10, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '10', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 11, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '11', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 12, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '12', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 13, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '13', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 14, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '14', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 15, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '15', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 16, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '16', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 17, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '17', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 18, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '18', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 19, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '19', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 20, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '20', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 21, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '21', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 22, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '22', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 23, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '23', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 24, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '24', data: "192.168.1.3"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 26, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '26', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 27, connection: 1
[13:56:48] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '27', data: "0"
[13:56:48] [DEBUG] cache_get_row_int - row: 0, field_idx: 28, connection: 1
Reply
#2

Admin field is index 4, not 5. In phpMyAdmin may start from 1 but in Pawn starts from 0. Subtract 1 in each field. For example:
pawn Код:
PlayerInfo[playerid][Admin] = cache_get_row_int(0, 5);
    PlayerInfo[playerid][Deaths] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][Nopm] = cache_get_row_int(0, 7);
    PlayerInfo[playerid][Muted] = cache_get_row_int(0, 8);
becomes:
pawn Код:
PlayerInfo[playerid][Admin] = cache_get_row_int(0, 4);
    PlayerInfo[playerid][Deaths] = cache_get_row_int(0, 5);
    PlayerInfo[playerid][Nopm] = cache_get_row_int(0, 6);
    PlayerInfo[playerid][Muted] = cache_get_row_int(0, 7);
do the same for the rest.
Reply
#3

try using fetch row format, and sscanf2, it's much easier
Reply
#4

@CoaPsyFactor - no. Don't do that ever again. If you want simplicity use orm, with orm_apply_cache. Tutorial is that way.

@OP: Consider switching to orm too, until it isn't too late to change all your code to that.
Reply
#5

Ok seems i fixed, now it doesn't load only the score, the exp and the money.

Any tip?

Log:

Quote:

[14:11:08] [DEBUG] Calling callback "OnAccountLoad"..
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 4, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '4', data: "5"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 5, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '5', data: "100"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 6, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '6', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 7, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '7', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 8, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '8', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 9, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '9', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 10, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '10', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 11, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '11', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 12, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '12', data: "5"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 13, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '13', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 14, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '14', data: "5"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 15, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '15', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 16, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '16', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 17, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '17', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 18, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '18', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 19, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '19', data: "0"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 20, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '20', data: "192"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 21, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '21', data: "192"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 22, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '22', data: "192"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 23, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '23', data: "192"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 24, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '24', data: "192.168.1.3"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 25, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '25', data: "5"
[14:11:08] [DEBUG] cache_get_row_int - row: 0, field_idx: 26, connection: 1
[14:11:08] [DEBUG] CMySQLResult::GetRowData - row: '0', field: '26', data: "0"
[14:11:08] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[14:11:08] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
[14:11:24] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `playerdata` SET Scores='0', Cash='0', Admin='5', Deaths=", callback: "(null)", format: "(null)"
[14:11:24] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[14:11:24] [DEBUG] mysql_tquery - scheduling query "UPDATE `playerdata` SET Scores='0', Cash='0', Admin='5', Deaths='100', Nopm='0', Muted='0', Vip='0', Warn='0', RegisterDate='0', Jailed='0', AdminActions='5', Cookies='0', Rank='5', VipTime='0', Class='0', PrototypesStolen='0', Exp='192', Duty='5', KillAsUsaTeam='0', KillAsGermanyTeam='0', KillAsItalyTeam='192', KillAsJapanTeam='192', KillAsMercTeam='192', KillAsMexicoTeam='192', DaysAlive='0' WHERE user='Face9000'"..
[14:11:24] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[14:11:24] [DEBUG] CMySQLQuery::Execute[()] - query was successful
[14:11:24] [DEBUG] CMySQLQuery::Execute[()] - no callback specified, skipping result saving
[14:11:24] [DEBUG] CMySQLQuery::Execute[()] - data being passed to ProcessCallbacks()
[14:11:24] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called

Reply
#6

Well, you don't set PlayerInfo[playerid][Scores] to any value before using it in SetPlayerScore. Same applies to cash. I don't know about your fields layout anything else to help with exp.

Before you proceed, consider
a) using fetching by field name
b) switching to orm
Reply
#7

Oh, you're right. Now it loads score and money. The only problem left is Exp, for some reason even i set to 50, when i relog i have 192.

UPDATE: Fixed Exp too, i was loading a wrong field.

Thanks @ all for helping.
Reply
#8

Quote:
Originally Posted by Misiur
Посмотреть сообщение
@CoaPsyFactor - no. Don't do that ever again. If you want simplicity use orm, with orm_apply_cache. Tutorial is that way.

@OP: Consider switching to orm too, until it isn't too late to change all your code to that.
Ok, orm is better idea, but from this tutorial, it does not look simpler than sscanf sscanf(string, "p<|>e<dsdsdsdsdsfffd>, PlayerInfos[ID]);

this is much simpler, but only bad thing is you need to be very careful with order of stats, stats must be ordered in enum just like in db
Reply
#9

Internally mysql plugin caching uses (IIRC) c++ vectors. There is no option to fetch full string when you are using caching. And if you aren't using threaded queries, it's really time to upgrade. mysql_pquery can really boost your script if you have more than 1 core CPU.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)