Help with MySQL
#1

Hello, I have a question:

pawn Код:
case 2:
        {
            if(!response) return Kick(playerid);
            GetPlayerName(playerid, pName, sizeof(pName));
            mysql_real_escape_string(inputtext, escapepass);
            format(Query, sizeof(Query), "SELECT `name` FROM users WHERE name = '%s' AND password = '%s'", pName, escapepass);
            mysql_query(Query);
            mysql_store_result();
            if(!mysql_num_rows())
            {
                ShowPlayerDialog(playerid...)
            }
            else if(mysql_num_rows() == 1)
            {
                format(Query, sizeof(Query), "SELECT * FROM users WHERE name = '%s'", pName);
                mysql_query(Query);
                mysql_store_result();
                while(mysql_fetch_row_format(Query,"|"))
                {
                    mysql_fetch_field_row(field, "score");
                    SetPlayerScore(playerid, strval(field));
                    mysql_fetch_field_row(field, "money");
                    GivePlayerMoney(playerid, strval(field));
                    mysql_fetch_field_row(field, "adminlevel");
                    PlayerInfo[playerid][pAdminLevel] = strval(field);
                    mysql_fetch_field_row(field, "gang");
                    PlayerInfo[playerid][Gang] = strval(field);
                }
            //  mysql_free_result();
                PlayerInfo[playerid][pLogged] = 1;
            }
        //  mysql_free_result();
        }
Where would I need to free the result? the first or the second commented mysql_free_result line? If I uncomment both, in the debug log it will say the result is already empty, but which one would be the best choice?

thanks
Reply
#2

I am not sure if there is actually a result if there arent any rows
but gernally I would free the result at the end of the code, also the second one

if than still the warning appears sometimes just change it
Reply
#3

ok I will.

Can you tell me which statements I need to free the result? I mean like update , select, delete etc.

Also, can you tell me why this won't attach?

pawn Код:
format(gName,sizeof(gName),"%s",GetGangTag(PlayerInfo[playerid][Gang]));
    PlayerLabel[playerid] = Create3DTextLabel(gName,White,30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(PlayerLabel[playerid],playerid, 0.0, 0.0, 0.7);
Did I forget anything?

Thank you btw
Reply
#4

Quote:

mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.

Source: mysql_free_result()
Reply
#5

ok thanks, btw should I be concered if it says in the log if the result is already free'd?

Also, what about my attach problem?
Reply
#6

Well, according to php you have to use mysql_free_result() if you are getting large results. Can you post the function "GetGangTag"?
Reply
#7

The GetGangTag works fine other places, but sure

pawn Код:
stock GetGangTag(GangID)
{
    new Query[150]; format(Query, sizeof(Query), "SELECT tag FROM gangs WHERE id = %d", GangID);
    mysql_query(Query);
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_get_field("tag",Query);
    }
    return Query;
}
Reply
#8

Try this

pawn Код:
stock GetGangTag(GangID)
{
    new Query[150]; format(Query, sizeof(Query), "SELECT tag FROM gangs WHERE id = %d", GangID);
    mysql_query(Query);
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        new _gangID;
        mysql_get_field("tag",Query);
        _gangID = strval(Query);
    }
    return _gangID;
}
Reply
#9

It didn't work , I don't think the stock is the problem?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)