mysql_function_query Problem
#1

Hi.
I have a problem.
I'm trying to load some info through "mysql_function_query", and it just doesn't work well.
This is the callback:
pawn Код:
public GetPlayerInfo(playerid) {
    new rows, fields, temp[70];
    cache_get_data(rows, fields);
    if (rows) {
        cache_get_row(0, 0, temp); // Password
        pInfo[playerid][pPass] = strval(temp);
        cache_get_row(0, 1, temp); // Male
        pInfo[playerid][pMale] = strval(temp);
        cache_get_row(0, 2, temp); // Origin
        format(pInfo[playerid][pOrigin], 30, "%s", temp);
        cache_get_row(0, 3, temp); // Skin
        pInfo[playerid][pSkin] = strval(temp);
        cache_get_row(0, 4, temp); // Money
        pInfo[playerid][pMoney] = strval(temp);
        cache_get_row(0, 5, temp); // Bank Money
        pInfo[playerid][pBankMoney] = strval(temp);
        cache_get_row(0, 6, temp); // Banned
        pInfo[playerid][pBanned] = strval(temp);
       
        if (pInfo[playerid][pBanned] == 1) {
            SCM(playerid, COLOR_ORANGE, "You are banned from this server!");
            Kick(playerid);
        }
    }
    return 1;
}
And it turns out to be wrong values.. For example "pInfo[playerid][pBank]" is 299 when is should be 5000...
I think I have some bugs in the code, could you guys help me?
Thanks
Reply
#2

pPass is a string, not a value, use format to get it.
Reply
#3

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
pPass is a string, not a value, use format to get it.
I'm using udb_hash so it's a number, I don't have problem with the pPass.
Reply
#4

Are you sure you table's are named 1,2,3,4,5,6?

And have you done:
pawn Код:
cache_get_field_content(0, "fieldname1", string1);
cache_get_field_content(0, "fieldname2", string2);
cache_get_field_content(0, "fieldname3", string3);
And something else, save time,(not much tho)

move this to the top before the rest of the data loads
pawn Код:
if (pInfo[playerid][pBanned] == 1) {
            SCM(playerid, COLOR_ORANGE, "You are banned from this server!");
            Kick(playerid);
        }
Reply
#5

I'm new with MySQL Caching&Threader queries, so.. :P
Nope, I didn't do this, and I don't know if they are names 1,2,3,4,5,6..
This is the callback code:
pawn Код:
format(szQuery, sizeof(szQuery), "SELECT `password`,`male`,`age`,`origin`,`skin`,`money`,`bankmoney`,`banned` FROM `users` WHERE `username` = '%s'", GN(playerid));
        mysql_function_query(dbHandle, szQuery, true, "GetPlayerInfo", "d", playerid);
I can't see any 1,2,3,4,5,6?
Reply
#6

I suggest you to take a look at this tutorial:

https://sampforum.blast.hk/showthread.php?tid=337810

Good luck!
Reply
#7

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
I suggest you to take a look at this tutorial:

https://sampforum.blast.hk/showthread.php?tid=337810

Good luck!
I did, but I didn't understand some parts.
Could you give me a replace code for the code I gave so I can learn?
Reply
#8

That's how everyone is here, saying "could you please give me the code so I can learn."

I agree on that you can learn from what you read. But first try it yourself, and show us the code YOU did. You can do it.
Reply
#9

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
That's how everyone is here, saying "could you please give me the code so I can learn."

I agree on that you can learn from what you read. But first try it yourself, and show us the code YOU did. You can do it.
nvm, worked I didn't even had to use "cache_get_content"
Reply
#10

I couldn't spot any flaws in your code, but there was one small optimization that could be done.
pawn Код:
public GetPlayerInfo(playerid)
{
    new rows, fields, temp[70];
    cache_get_data(rows, fields);
   
    if (rows) {
        // you can just store origin into the var straight away without needing to format
        cache_get_field_content(0, "Origin", pInfo[playerid][pOrigin]);
        cache_get_field_content(0, "Password", temp);                       pInfo[playerid][pPass] = strval(temp);
        cache_get_field_content(0, "Male", temp);                           pInfo[playerid][pMale] = strval(temp);
        cache_get_field_content(0, "Skin", temp);                           pInfo[playerid][pSkin] = strval(temp);
        cache_get_field_content(0, "Money", temp);                          pInfo[playerid][pMoney] = strval(temp);
        cache_get_field_content(0, "BankMoney", temp);                      pInfo[playerid][pBankMoney] = strval(temp);
        cache_get_field_content(0, "Banned", temp);                         pInfo[playerid][pBanned] = strval(temp);
       
        if (pInfo[playerid][pBanned] == 1) {
            SCM(playerid, COLOR_ORANGE, "You are banned from this server!");
            Kick(playerid);
        }
    }
    return 1;
}
Your 'can't login' problem must be somewhere else.


EDIT: woops, too late. I'll leave my post though.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)