24.11.2012, 11:20
Solutions such as
should be considered obsolete and bad in many many cases since it is a clear hint that the code could use some restructuring and better architecture in general. I have seen plenty of functions like this being called even THREE or more times in one small function whereas only one query would actually suffice or if proper coding methods would be used, there would be no need to make a query to the MySQL server to get frequently-accessed data, it would rather be pre-stored somewhere (arrays, dynamic memory, whatever).
pawn Код:
stock GetPlayerAttribute(playerid)
{
new ID;
mysql_query("SELECT attribute FROM players_table WHERE name = 'Player'");
mysql_store_result();
if(mysql_num_rows())
{
new temp[12];
mysql_fetch_row(temp);
mysql_free_result();
return strval(temp);
}
mysql_free_result();
return false;
}
// tl;dr - this code is crappy...