Loading stats with MySQL
#1

I was just wondering which is more efficient for loading MySQL stats

1) Using the method used to load player stats upon login found in Moderntopia and many other login systems

example taken from Moderntopia 1.0 script:

Код:
...
// The rcnt values here represent the order of the columns in the characters table, so don't mess with them
// If you add a column to the table, just add a new line with a +1 rcnt to the block below
// Start it at 3 to skip the first few records we don't need (id, player name, password)
if (rcnt == 3) PlayerInfo[playerid][pLevel] = strval(Field);
if (rcnt == 4) PlayerInfo[playerid][pAdmin] = strval(Field);
if (rcnt == 5) PlayerInfo[playerid][pDonateRank] = strval(Field);
...
If I understand this correctly, Moderntopia 1.0 fetches a giant string containing all the data for a player's account in one single query.
Then sorts it out by tokenizing (strtok) the string into little strings which are set into their appropriate variables via "rcnt"'s.

2) My method would look like this:

Код:
...
PlayerInfo[playerid][pLevel] = MySQLGetInt(playerSQLID, playerDatabase, "pLevel");
PlayerInfo[playerid][pAdmin] = MySQLGetInt(playerSQLID, playerDatabase, "pAdmin");
PlayerInfo[playerid][pDonateRank] = MySQLGetInt(playerSQLID, playerDatabase, "pDonateRank");
...
Код:
MySQLGetInt(sqlid, database[], property[])
{
	new
		query[128],
		strid[32],
		value;
		
	format(query, sizeof(query), "SELECT %s FROM %s WHERE ID = %d LIMIT 1", property, database, sqlid);
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows() == 1)
	{
		mysql_fetch_row(strid);
		value = strval(strid);
		mysql_free_result();
		//printf("[Get] %s = %d", property, value);
		return value;
	}
	else
	{
	  mysql_free_result();
	  //printf("Property \"%s\" not found.", property);
	  return 0;
	}
}
As you can see, my method makes one query for every variable loaded. No strtok, no giant strings, but a load of queries, lol.

Although the method I have chosen is easier (imho), especially when adding and removing stats, I wonder whether it makes my code significantly less efficient.
Reply


Messages In This Thread
Loading stats with MySQL - by ledzep - 29.06.2009, 08:53
Re: Loading stats with MySQL - by ledzep - 29.06.2009, 10:38
Re: Loading stats with MySQL - by krisk - 29.06.2009, 10:41
Re: Loading stats with MySQL - by ledzep - 29.06.2009, 10:45
Re: Loading stats with MySQL - by krisk - 29.06.2009, 10:46
Re: Loading stats with MySQL - by G_ROW_Chez - 29.06.2009, 11:59
Re: Loading stats with MySQL - by ledzep - 29.06.2009, 12:48

Forum Jump:


Users browsing this thread: 1 Guest(s)