PHP Code:
set_db_field(fieldname, value)
{
mysql_query(level.mysql_connection, "INSERT INTO `"+level.table+"`(`user_guid`, `"+fieldname+"`) VALUES ('"+self.guid+"', '"+value+"') ON DUPLICATE KEY UPDATE `"+fieldname+"`='"+value+"'");
}
Keep in mind that above code does NOT do any sanity checks on input, so mysql injections are still possible. Also it might try to set a non-existing column so check your inputs. Also, it sets values in mysql to a string. If you're storing kills, you might wanna change it to integers/floats
PHP Code:
get_db_field(fieldname)
{
if(isDefined(self.isbot))
return undefined;
mysql_query(level.mysql_connection, "SELECT fieldname FROM `"+level.table+"` WHERE `user_guid`= '"+self.guid+"' LIMIT 1");
r = mysql_store_result(level.mysql_connection);
if(isdefined(r))
{
row = mysql_fetch_row(result);
if(isdefined(row) && isdefined(row[0]))
{
mysql_free_result(r);
return row[0];
}
mysql_free_result(r);
}
return undefined;
}
Above code will not check for columnname correctness either, so check your inputs. Also it returns undefined if the player is either a bot or the row doesnt exist at all