forward updateStats(playerid); public updateStats(playerid) { new query[128], playername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, sizeof(playername)); mysql_format(mysql, query, sizeof(query), "SELECT `Money` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername); mysql_tquery(mysql, query, "", "i", playerid); Player[playerid][Money] = cache_get_field_content_int(0, "Money"); GivePlayerMoney(playerid, Player[playerid][Money]); SendClientMessage(playerid, -1, "Updated"); return 1; }
forward updateStats(playerid); public updateStats(playerid) { new query[128], playername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, sizeof(playername)); mysql_format(mysql, query, sizeof(query), "SELECT `Money` FROM `accounts` WHERE `Name` = '%s' LIMIT 1", playername); mysql_query(mysql, query); if(cache_num_rows()) { Player[playerid][Money] = cache_get_field_content_int(0, "Money"); GivePlayerMoney(playerid, Player[playerid][Money]); SendClientMessage(playerid, -1, "Updated"); } return 1; }
Код:
forward updateStats(playerid); public updateStats(playerid) { new query[128], playername[MAX_PLAYER_NAME]; GetPlayerName(playerid, playername, sizeof(playername)); mysql_format(mysql, query, sizeof(query), "SELECT `Money` FROM `accounts` WHERE `Name` = '%s' LIMIT 1", playername); mysql_query(mysql, query); if(cache_num_rows()) { Player[playerid][Money] = cache_get_field_content_int(0, "Money"); GivePlayerMoney(playerid, Player[playerid][Money]); SendClientMessage(playerid, -1, "Updated"); } return 1; } |
@F1N4L: You should store the cache result id and at the end to delete it to avoid memory leaks. Non-threaded queries are not very recommended either.
|
Could you give me an example? Are you suggesting a loop?
I use this way, I have no problems, but if there is a safer way to get the values in the DB ... |
mysql_tquery needs a callback to call the cache functions there otherwise using it directly will results in warnings for no active cache.
I can't understand the purpose of your code though. Why don't you simply give the money once when the login? @F1N4L: You should store the cache result id and at the end to delete it to avoid memory leaks. Non-threaded queries are not very recommended either. |