Results 1 to 10 of 11

Thread: Store player informations with MySQL.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    set_db_field(fieldnamevalue
    {
        
    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");
        
    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
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  2. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    ebusiangamers (6th July 2015),kung foo man (6th July 2015)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •