MySQL question
#1

Hey guys,
I'm changing my saving method from Dini to MySQL
I have finished the registration & login and now I have to modify all the offline commands
Offline Bans, Offline Admin removals, Offline leadership removals etc etc

My question is,
How can I do this:
PHP код:
    format(filesizeof(file), "users/%s.ini"playerb);
    if(!
dini_Exists(file)) return SendClientMessage(playeridCOLOR_GREY"Player name not found.");
    if(
PlayerInfo[playerid][pAdmin] < dini_Int(file"Admin")) return SendClientMessage(playeridCOLOR_GREY"Player has a higher admin level than you."); 
In a MySQL way WITHOUT using further callbacks
Reply
#2

Using mysql_query i guess.
pawn Код:
"SELECT * FROM `table` WHERE `condition` = 'match'"
And then just check if there are any rows or not using cache_get_row_count (0 means not existing).

You can also checkout sql.inc which allows you MySQL with SQLite syntax and lot more, in case you are interested or unaware.
Reply
#3

pawn Код:
new
    Cache:result,
    Query[128]
;

mysql_format(MySQL, Query, sizeof(Query), "SELECT `Admin` FROM `Users` WHERE `Username` = '%e'", playerb);
result = mysql_query(MySQL, Query);

if(cache_get_row_count(MySQL))
{
    new
        adminLevel
    ;

    adminLevel = cache_get_row_int(0, 0, MySQL);
       
    if(PlayerInfo[playerid][pAdmin] < adminLevel)
    {
        SendClientMessage(playerid, COLOR_GREY, "Player has a higher admin level than you.");
    }
    else
    {
        mysql_format(MySQL, Query, sizeof(Query), "UPDATE `Users` SET `Admin` = %d WHERE `Username` = '%e'", newLevel, playerb);
        mysql_tquery(MySQL, Query, "", "");
    }
}
cache_delete(result);
Untested but it will give you the idea.
Reply
#4

Quote:
Originally Posted by ]Rafaellos[
Посмотреть сообщение
pawn Код:
new
    Cache:result,
    Query[128]
;

mysql_format(MySQL, Query, sizeof(Query), "SELECT `Admin` FROM `Users` WHERE `Username` = '%e'", playerb);
result = mysql_query(MySQL, Query);

if(cache_get_row_count(MySQL))
{
    new
        adminLevel
    ;

    adminLevel = cache_get_row_int(0, 0, MySQL);
       
    if(PlayerInfo[playerid][pAdmin] < adminLevel)
    {
        SendClientMessage(playerid, COLOR_GREY, "Player has a higher admin level than you.");
    }
    else
    {
        mysql_format(MySQL, Query, sizeof(Query), "UPDATE `Users` SET `Admin` = %d WHERE `Username` = '%e'", newLevel, playerb);
        mysql_tquery(MySQL, Query, "", "");
    }
}
cache_delete(result);
Untested but it will give you the idea.
Well unfortunately I didn't know about that Cache: variable
I'll try it out

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Using mysql_query i guess.
pawn Код:
"SELECT * FROM `table` WHERE `condition` = 'match'"
And then just check if there are any rows or not using cache_get_row_count (0 means not existing).

You can also checkout sql.inc which allows you MySQL with SQLite syntax and lot more, in case you are interested or unaware.
Thanks, I'll take a look
Reply
#5

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Well unfortunately I didn't know about that Cache: variable
I'll try it out
Well, if you want it WITHOUT further callbacks, you have to use Cache.
Reply
#6

I'd still go with callbacks rather than using cached variables. It's way more easier (for me). And instead of creating way too many callbacks, simply create one callback using separate thread ids. For me, it's pretty faster.
Reply
#7

Quote:
Originally Posted by Sjn
Посмотреть сообщение
I'd still go with callbacks rather than using cached variables. It's way more easier (for me). And instead of creating way too many callbacks, simply create one callback using separate thread ids. For me, it's pretty faster.
I thought about creating a callback for all offline modification commands, But I don't know how to set an ID for each CMD, It would be great if you explain me
Reply
#8

I have many result ids defined in the following ways for separate threads.
PHP код:
#define SQL_THREAD_NONE             0 // Thread used for executing normal queries (no result)
#define SQL_THREAD_OFFLINEBAN       1
#define SQL_THREAD_OFFLINELEVEL     2 
And for a callback I have something like
PHP код:
// You can add other parameters in the public callback for more values
forward OnQueryReceive(result_idint_valuestring[], handle);
public 
OnQueryReceive(result_idint_valuestring[], handle)
{
    new 
rowsfields;

    if (
result_id != SQL_THREAD_NONE// If the thread has no result, just execute the query without fetching the data
    
{
        
cache_get_data(rowsfields);
    }
    
    switch (
result_id)
    {
        case 
SQL_THREAD_OFFLINEBAN:
        {
            if (
rows)
            {
                
// Row exists, code here
            
}
            else
            {
                
// Row doesn't exist, return error or something
            
}
        }
        
// More threads bellow
    
}

    return 
1;

And for executing the query
PHP код:
mysql_tquery(handleQuery"OnQueryReceive""iis"SQL_THREAD_OFFLINEBANinteger_valstring_val); 
This is how I use them, all of my queries gets executed through one callback using separated thread ids.
Reply
#9

what's mean integer_val and string_val

i want to trasfer this from mysql r5 to mysql r 33+

PHP код:
    format(querysizeof(query), "SELECT * FROM `players` WHERE `name` = '%s'"PlayerName);
    
mysql_query(queryMYSQL_QUERY_CONNECTplayerid); 
Reply
#10

BUMP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)