Save & Load Query Problem.
Hello.
I have problem with a Load and Save Query.
PHP Code:
public MySql_Init() { g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db); new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error)); if(SqlConnection == Empty_Handle) { set_fail_state(g_Error); } new Handle:Queries; Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS dr_stats (nick varchar(255), auth varchar(255), elud int(11), money int(11))"); if(!SQL_Execute(Queries)) { SQL_QueryError(Queries,g_Error,charsmax(g_Error)); set_fail_state(g_Error); } SQL_FreeHandle(Queries); SQL_FreeHandle(SqlConnection); }
public LoadData(id) { new szSteamId[32], szTemp[512]; get_user_authid(id, szSteamId, charsmax(szSteamId)); new Data[1]; Data[0] = id; //we will now select from the table `tutorial` where the steamid match format(szTemp,charsmax(szTemp),"SELECT * FROM `dr_stats` WHERE `auth` = '%s'", szSteamId); SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1); }
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { if(FailState == TQUERY_CONNECT_FAILED) { log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error); } else if(FailState == TQUERY_QUERY_FAILED) { log_amx("Load Query failed. [%d] %s", Errcode, Error); }
new id; id = Data[0]; if(SQL_NumResults(Query) < 1) { //.if there are no results found new szSteamId[32]; get_user_authid(id, szSteamId, charsmax(szSteamId)); // get user's steamid // if its still pending we can't do anything with it if (equal(szSteamId,"ID_PENDING")) return PLUGIN_HANDLED; new szTemp[512]; new name[33]; get_user_name(id, name, 32); format(szTemp,charsmax(szTemp),"INSERT INTO `dr_stats` (`nick`, `auth`, `elud`, `money`) VALUES ('%s','%s','0','0');",name, szSteamId); SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp); } else { // if there are results found g_Lifes[id] = SQL_ReadResult(Query, 1); } return PLUGIN_HANDLED; }
public SaveData(id) { new szSteamId[32], szTemp[512]; get_user_authid(id, szSteamId, charsmax(szSteamId)); // Here we will update the user hes information in the database where the steamid matches. format(szTemp,charsmax(szTemp),"UPDATE `dr_stats` SET `elud` = '%s' WHERE `dr_stats`.`auth` = '%s';",g_Lifes[id], szSteamId); SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp); }
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { SQL_FreeHandle(Query); return PLUGIN_HANDLED; }
If i connect to the server, it doesnt get informatsion from sql database and it wont save data if i change the Map.
|