I have a problem with calling SQL queries and storing data in global variables. I have a test function that is called when a client types in a command in his console. I wanted to be able to store this player's data in a global array for his specific player id in the array. (Array[id])
The problem comes in when I call the SQL_Threadquery, which in turn uses a query handler with set parameters. I have no idea I'm supposed to pass a player's id into the handler function, or if it is even possible, so I decided to use a global variable to store the retrieved information to carry back into the function that called the Threadquery in the first place, which has an instance of the player's playerid.
I noticed that no data was returning when I printed it to the screen for the player to see, so I did a test, and printed out the result in two different places: one local, one global. The local print is the correct data, but the global print fails miserably.
Here are the functions...
PHP Code:
public SQL_CallQuery(Query[],Type)
{
copy(SQL_CurrentQuery,511,Query)
SQL_CurrentType=Type
SQL_ThreadQuery(SQL_Tuple,"SQL_QueryHandle",Query)
}
PHP Code:
public SQLTEST(id)
{
new Query[256]
format(Query,255,"SELECT JobID FROM playerdata WHERE SteamID='%s'",UserSteamID[id])
SQL_ResultInt=1337
SQL_CallQuery(Query,1)
client_print(id,print_chat,"Global JobID: %d",SQL_ResultInt)
return PLUGIN_HANDLED
}
PHP Code:
public SQL_QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
return set_fail_state("Could not connect to SQL database.")
else if(FailState == TQUERY_QUERY_FAILED)
return set_fail_state("Query failed.")
if(Errcode)
return log_amx("Error on query: %s",Error)
new Number=250
while(SQL_MoreResults(Query))
{
Number=SQL_ReadResult(Query,0)
client_print(0,print_chat,"Local JobID: %d",Number)
SQL_NextRow(Query)
}
SQL_ResultInt=Number
return PLUGIN_CONTINUE
}
Ignore the strange complexity of the functions calling functions and blah blah, I was trying stuff to try and get this to work.
Note: Global JobID print is 500, local is 1.
1 is the correct JobID.