Edit: before linking to me tutorials how to use search button, let me tell that I already did it and I didn't find anything to help myself.
|
Sorry to burst your bubble but there's a tutorial in the BlueG MySQL thread that explains everything.
https://sampforum.blast.hk/showthread.php?tid=337810 Next time you just need to search harder. |
If you know almost nothing about MySQL, you shouldn't be using it!
|
new query[128];
format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s'", GetName(playerid));
mysql_function_query(dbHandle, query, true, "LoadPlayerStats", "i", playerid);
forward LoadPlayerStats(playerid);
public LoadPlayerStats(playerid)
{
new rows, fields;
cache_get_data(rows, fields);
if(rows) //If a row with the player name was found
{
}
else //If not
{
}
return 1;
}
If you know almost nothing about MySQL, you shouldn't be using it!
|
You have two servers running the same gamemode, but using a MySQL server to store common data. In this case we will be handling player house data. You want this data to be loaded into the game mode all the time so that if a player buys a house on server A, server B will also show the house icon. Well if you're running a fairly popular server then you will end up having a lot of housing data. You want this data synchronized about every minute (for purpose of this example), however this is causing much lag while the plugin is going to the MySQL server to fetch the data. The script is waiting for the plugin to get the data before it can do anything else. So player updates are frozen during this time.
This is where threaded queries would help out. If you were to launch a threaded query to fetch the house data the plugin would run the query, while allowing the script to execute. Once the query has ran and the plugin has all the data, it will execute the specified callback in the script. Once this callback gets executed then your script will get all the data from the query, and you can process it as efficiently as you can.Any questions?
For example?
pawn Код:
|
Threading means that the plugin will go and run the query while allowing your script to resume execution.
Scenario: You have two servers running the same gamemode, but using a MySQL server to store common data. In this case we will be handling player house data. You want this data to be loaded into the game mode all the time so that if a player buys a house on server A, server B will also show the house icon. Well if you're running a fairly popular server then you will end up having a lot of housing data. You want this data synchronized about every minute (for purpose of this example), however this is causing much lag while the plugin is going to the MySQL server to fetch the data. The script is waiting for the plugin to get the data before it can do anything else. So player updates are frozen during this time. This is where threaded queries would help out. If you were to launch a threaded query to fetch the house data the plugin would run the query, while allowing the script to execute. Once the query has ran and the plugin has all the data, it will execute the specified callback in the script. Once this callback gets executed then your script will get all the data from the query, and you can process it as efficiently as you can.Any questions? |
The plugins are not provided for people to learn SQL, they are provided for people who already know SQL. It is an incredibly powerful language, but one that is very hard to get right, even for the experts. If you learn as you go, there's a high chance you will miss out on all the information regarding potential security holes littering your code as a result of using it (and no, one basic tutorial mentioning escaping strings is not adequate protection). 90% of the SQL on these forums is insecure, inefficient rubbish because people tried to learn on the job instead of learning first then using that knowledge.
|