SA-MP Forums Archive
Help with MySQL - 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: Help with MySQL (/showthread.php?tid=294363)



Help with MySQL - Cowboy - 01.11.2011

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


AW: Help with MySQL - Nero_3D - 01.11.2011

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


Re: Help with MySQL - Cowboy - 01.11.2011

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


Re: Help with MySQL - Pinguinn - 01.11.2011

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()


Re: Help with MySQL - Cowboy - 01.11.2011

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?


Re: Help with MySQL - Pinguinn - 01.11.2011

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


Re: Help with MySQL - Cowboy - 01.11.2011

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;
}



Re: Help with MySQL - Pinguinn - 01.11.2011

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;
}



Re: Help with MySQL - Cowboy - 01.11.2011

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