20.02.2014, 13:49
Ah, ok. When you are using unthreaded queries, the server has to wait until you get result. When I'm saying server, that means all commands, and everything will be unresponsive for all players. That's why we are using threaded queries. It creates separate thread in your server's CPU, and calls back to your script when the result is ready (at least that's how I understand it). Lag eliminated, but requires you to provide a callback - function which will be called after retrieving results. It has to be a public function, like with timers. So, your code has to look like:
I used %e and mysql_format - ****** sql injection to learn about dangers of using %s instead %e with strings.
pawn Код:
stock GetName(playerid)
{
new AccName[MAX_PLAYER_NAME];
GetPlayerName(playerid, AccName, sizeof(AccName));
return pName;
}
public OnPlayerDisconnect(playerid, reason)
{
mysql_format(sqldb, query, sizeof(query), "INSERT INTO accounts (accname) VALUES ('%e')", GetName(playerid));
mysql_tquery(sqldb, query, "InsertCallback", "d", playerid);
return 1;
}
forward InsertCallback(playerid);
public InsertCallback(playerid)
{
PlayerInfo[playerid][pSQLID] = cache_insert_id(sqldb);
printf("Player %d was saved with dbID %d", playerid, PlayerInfo[playerid][pSQLID]);
return 1;
}