31.07.2016, 03:19
Hello guys!
I'm having problems trying to convert unthreaded queries to threaded queries.
Orginally in unthreaded I was simply asked to put the "LoadFunctions()" under OnGameModeInit. But after looking at tutorial I learned I can pass it under callback something like this.
THREADED QUEIRIES ATTEMPT:
UNTHREAD QUERIES
I'm trying to convert to threaded queries, but I'm doing it wrong as it doesn't work at all. If someone could help me convert it. That'd be great!
My table looks like this.
I'm having problems trying to convert unthreaded queries to threaded queries.
Orginally in unthreaded I was simply asked to put the "LoadFunctions()" under OnGameModeInit. But after looking at tutorial I learned I can pass it under callback something like this.
THREADED QUEIRIES ATTEMPT:
PHP код:
public OnGameModeInit()
{
SetGameModeText("MySQL - Server");
new query[400];
for (new id; id < MAX_FACTIONS; id++)
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `Factions` WHERE `ID` = %d LIMIT 1", id);
mysql_tquery(mysql, query, "LoadFactions", "");
}
mysql_log(LOG_ALL);
mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
if(mysql_errno() != 0)
{
printf("[MySQL] The connection has failed.");
}
else
{
printf("[MySQL] The connection was successful.");
}
return true;
}
forward LoadFactions();
public LoadFactions()
{
new rows, fields;
cache_get_data(rows,fields);
if(rows)
{
cache_get_field_content_int(0, "ID");
cache_get_field_content(0,"Name",Factions[Total_Factions_Created][Name]);
cache_get_field_content(0,"Rank1",Factions[Total_Factions_Created][Rank1]);
cache_get_field_content(0,"Rank2",Factions[Total_Factions_Created][Rank2]);
cache_get_field_content(0,"Rank3",Factions[Total_Factions_Created][Rank3]);
cache_get_field_content(0,"Rank4",Factions[Total_Factions_Created][Rank4]);
cache_get_field_content(0,"Rank5",Factions[Total_Factions_Created][Rank5]);
Total_Factions_Created++;
}
printf("> %d factions have been loaded from the database.", Total_Factions_Created); // Prints out the information of how many factions created
return 1;
}
PHP код:
public OnGameModeInit()
{
LoadFactions();
}
stock LoadFactions()
{
new query[400];
for(new id; id < MAX_FACTIONS; id++) // Goes through all the slots, looking for the data
{
format(query, sizeof(query), "SELECT * FROM Factions WHERE ID = %d", id); // Selects all the information from the table
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
if(mysql_fetch_row_format(query,"|"))
{
sscanf(query, "p<|>e<is[64]ds[32]s[32]s[32]s[32]s[32]>",Factions[id]); // SSCANF seperates the data into the variables
Total_Factions_Created++; // Counts the factions created
}
}
printf("> %d factions have been loaded from the database.", Total_Factions_Created); // Prints out the information of how many factions created
return 1;
}
My table looks like this.