Mysql cache
#1

Hello, I'm trying to convert to mysql r7 with cache functions but for some reason it's saying my money and admin 52 when actually my money is 0 and my admin is 4

pawn Код:
public OnPlayerConnect(playerid)
{
    mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");
    return 1;
}

forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid) {
    new rows, fields;
    cache_get_data(rows, fields, Gconnection);
    if(rows)
    {
        new temp[12];
        cache_get_field_content(0, "admin", temp);
        printf("thefatshizms admin level is %d", temp);
        cache_get_field_content(0, "money", temp);
        printf("thefatshizms money is %d", temp);
    }
    return 1;

}
Reply
#2

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

That's what I've been using to convert. But to me my code looks "fine" so I don't know if I have missed anything :/
Reply
#4

mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");

`username`='thefatshizms'

Why?

You should put player name..

format (query, sizeof query, "SELECT * FROM users WHERE `username`='%s'", player_name);

now change
mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");

to

mysql_function_query(Gconnection, query, true, "OnPlayerLogin", "d", "playerid");
Reply
#5

Ahem, I know how to do this, if didn't I wouldn't be converting i would be trying to learn it. I'm doing this because i like to TEST functions I haven't used yet before actually making something with it.

just used this:

pawn Код:
public OnPlayerConnect(playerid)
{
    mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");
    return 1;
}

forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid) {
    new rows, fields;
    cache_get_data(rows, fields, Gconnection);
    if(rows)
    {
        new temp[12];
        cache_get_row(0, 8, temp);
        printf("thefatshizms admin level is %d", temp);
        cache_get_row(0, 3, temp);
        printf("thefatshizms money is %d", temp);
    }
    return 1;

}
Still saying 52, I can give a screen shot of my table if needed.
Reply
#6

Код:
public OnPlayerConnect(playerid)
{
    mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");
    return 1;
}

forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid) {
    new rows, fields;
    cache_get_data(rows, fields, Gconnection);
    if(rows)
    {
        new temp[12], temp2;
        cache_get_field_content(0, "admin", temp);
        temp2 = strval(temp);
        printf("thefatshizms admin level is %d", temp2);
        cache_get_field_content(0, "money", temp);
        temp2 = strval(temp);
        printf("thefatshizms money is %d", temp2);
    }
    return 1;

}
Reply
#7

Quote:
Originally Posted by Tommyx3
Посмотреть сообщение
Код:
public OnPlayerConnect(playerid)
{
    mysql_function_query(Gconnection, "SELECT * FROM users WHERE `username`='thefatshizms'", true, "OnPlayerLogin", "d", "playerid");
    return 1;
}

forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid) {
    new rows, fields;
    cache_get_data(rows, fields, Gconnection);
    if(rows)
    {
        new temp[12], temp2;
        cache_get_field_content(0, "admin", temp);
        temp2 = strval(temp);
        printf("thefatshizms admin level is %d", temp2);
        cache_get_field_content(0, "money", temp);
        temp2 = strval(temp);
        printf("thefatshizms money is %d", temp2);
    }
    return 1;

}
Thanks, forgot to turn the string back into an int!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)