format(file, sizeof(file), "users/%s.ini", playerb);
if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_GREY, "Player name not found.");
if(PlayerInfo[playerid][pAdmin] < dini_Int(file, "Admin")) return SendClientMessage(playerid, COLOR_GREY, "Player has a higher admin level than you.");
"SELECT * FROM `table` WHERE `condition` = 'match'"
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);
pawn Код:
|
Using mysql_query i guess.
pawn Код:
You can also checkout sql.inc which allows you MySQL with SQLite syntax and lot more, in case you are interested or unaware. |
Well unfortunately I didn't know about that Cache: variable
I'll try it out |
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.
|
#define SQL_THREAD_NONE 0 // Thread used for executing normal queries (no result)
#define SQL_THREAD_OFFLINEBAN 1
#define SQL_THREAD_OFFLINELEVEL 2
// You can add other parameters in the public callback for more values
forward OnQueryReceive(result_id, int_value, string[], handle);
public OnQueryReceive(result_id, int_value, string[], handle)
{
new rows, fields;
if (result_id != SQL_THREAD_NONE) // If the thread has no result, just execute the query without fetching the data
{
cache_get_data(rows, fields);
}
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;
}
mysql_tquery(handle, Query, "OnQueryReceive", "iis", SQL_THREAD_OFFLINEBAN, integer_val, string_val);
format(query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%s'", PlayerName);
mysql_query(query, MYSQL_QUERY_CONNECT, playerid);