SA-MP Forums Archive
Question about MySQL - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question about MySQL (/showthread.php?tid=618393)



Question about MySQL - DTV - 05.10.2016

I was looking at a tutorial for a register/login system that was made with the latest version of MySQL and noticed within the player enum was something called Cache_ID. I'm just curious what the benefit of that is as I can't seem to find what it's use is for, even after looking through the tutorial.


Re: Question about MySQL - Rdx - 05.10.2016

Can be used for save data you received from mysql query. For example, you can use query, save cache, and use it in another code place without next query.


Re: Question about MySQL - DTV - 06.10.2016

Is there a small example that I could see to understand it a bit better?


Re: Question about MySQL - Rdx - 06.10.2016

1. Player enum:

Cache: Cache_ID

2. Query:

Код:
mysql_format(g_SQL, query, sizeof query, "SELECT * FROM `players` WHERE `username` = '%e' LIMIT 1", Player[playerid][Name]);
mysql_tquery(g_SQL, query, "OnPlayerDataLoaded", "dd", playerid, g_MysqlRaceCheck[playerid]);
3. OnPlayerDataLoaded (loading password only):

Код:
cache_get_value(0, "password", Player[playerid][Password], 65);
and saving cache:

Код:
Player[playerid][Cache_ID] = cache_save();
4. Now you can use data from our query in other place of code, no more need to mysql_tquery. So we are loading rest by this code:

Код:
cache_set_active(Player[playerid][Cache_ID]);
cache_get_value_int(0, "kills", Player[playerid][Kills]);
5. No need that data anymore? Delete cache.

Код:
cache_delete(Player[playerid][Cache_ID]);
Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;



Re: Question about MySQL - DTV - 06.10.2016

Oh alright, that makes sense. Thanks for the help.