MySQL R7 functions
#1

Hi,

I was wondering how to register/load a user with the new R7 functions.

Do I need to use the mysql_query function (threads) or the mysql_format or mysql_function_query?
pawn Код:
#define THREAD_MYSELECT  (1)

mysql_query("SELECT * FROM `mytable` WHERE condition=true", THREAD_MYSELECT, playerid);
OR
pawn Код:
new szDestination[100];

mysql_format(connectionHandle, szDestination, "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
mysql_query(szDestination);
OR
pawn Код:
stock CheckAccount(playerid) //VincentDunn
{
    new query[82];
   
    format(query, sizeof(query), "SELECT id, pass, salt FROM `users` WHERE `name` = '%s' LIMIT 1", returnName(playerid));
    mysql_function_query(g_Handle, query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

forward OnAccountCheck(playerid);
public OnAccountCheck(playerid) //VincentDunn
{
    if(playerid != INVALID_PLAYER_ID) { // if the player is still connected
   
        new rows, fields;
        cache_get_data(rows, fields, g_Handle);
       
        if(rows) {
            g_PlayerInfo[playerid][pSQLid] = cache_get_row_int(0, 0, g_Handle);

            cache_get_row(0, 1, g_PlayerInfo[playerid][pPass], g_Handle, 130); // whirlpool length + 1
            cache_get_row(0, 2, g_PlayerInfo[playerid][pSalt], g_Handle, SALT_LENGTH+1);
           
            ShowDialog(playerid, Show:Login, DIALOG_STYLE_PASSWORD, "{1564F5}Login", "Type in your password below to log in.", "Okay", "Cancel");
        }
       
        else {
            ShowDialog(playerid, Show:Register, DIALOG_STYLE_PASSWORD, "{1564F5}Register", "Type in a password below to register an account.", "Okay", "Cancel");
        }
    }
    return 1;
}
Reply
#2

Quote:
Originally Posted by Loot
Посмотреть сообщение
Hi,

I was wondering how to register/load a user with the new R7 functions.

Do I need to use the mysql_query function (threads) or the mysql_format or mysql_function_query?
pawn Код:
#define THREAD_MYSELECT  (1)

mysql_query("SELECT * FROM `mytable` WHERE condition=true", THREAD_MYSELECT, playerid);
OR
pawn Код:
new szDestination[100];

mysql_format(connectionHandle, szDestination, "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
mysql_query(szDestination);
OR
pawn Код:
stock CheckAccount(playerid) //VincentDunn
{
    new query[82];
   
    format(query, sizeof(query), "SELECT id, pass, salt FROM `users` WHERE `name` = '%s' LIMIT 1", returnName(playerid));
    mysql_function_query(g_Handle, query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

forward OnAccountCheck(playerid);
public OnAccountCheck(playerid) //VincentDunn
{
    if(playerid != INVALID_PLAYER_ID) { // if the player is still connected
   
        new rows, fields;
        cache_get_data(rows, fields, g_Handle);
       
        if(rows) {
            g_PlayerInfo[playerid][pSQLid] = cache_get_row_int(0, 0, g_Handle);

            cache_get_row(0, 1, g_PlayerInfo[playerid][pPass], g_Handle, 130); // whirlpool length + 1
            cache_get_row(0, 2, g_PlayerInfo[playerid][pSalt], g_Handle, SALT_LENGTH+1);
           
            ShowDialog(playerid, Show:Login, DIALOG_STYLE_PASSWORD, "{1564F5}Login", "Type in your password below to log in.", "Okay", "Cancel");
        }
       
        else {
            ShowDialog(playerid, Show:Register, DIALOG_STYLE_PASSWORD, "{1564F5}Register", "Type in a password below to register an account.", "Okay", "Cancel");
        }
    }
    return 1;
}
The last one!
Reply
#3

Quote:
Originally Posted by Wizzy951
Посмотреть сообщение
The last one!
Then where do I use the threaded function?
Reply
#4

Quote:
Originally Posted by Loot
Посмотреть сообщение
Then where do I use the threaded function?
This tutorial is quite good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)