Results 1 to 10 of 11

Thread: Store player informations with MySQL.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Private
    Join Date
    Jun 2015
    Posts
    15
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Thank you for replying.
    1. I'm new to MySQL so I'm kinda struggling with it.
    2. Will try and make a report on it.
    3. I'm testing CoDUOExtended (made by phpcod, not yet released), thus I can just use provided functions/methods.
    4. I use phpmyadmin to confirm: no changes were made in the database but still, my connection exists: if not, the game crashes.
    PHP Code:
    mysql_stuff() 
    {
        
    level.host getCvar("mysql_host"); 
        
    level.pass getCvar("mysql_password"); 
        
    level.database getCvar("mysql_database"); 
        
    level.user getCvar("mysql_user");  
        
    level.table getCvar("mysql_table");
        
        
    level.mysql_connection xmysql_connect(level.hostlevel.userlevel.passlevel.database3306);    
        
        if(!
    isdefined(level.mysql_connection) || level.mysql_connection == 0
        {
            
    logprint("mysql not defined");
            return;
        }
        else
            
    logprint("MySQL: Connect to "level.host +" successfully");

    5. I forgot it.

  2. The Following User Says Thank You to ebusiangamers For This Useful Post:

    kung foo man (4th July 2015)

  3. #2
    Private
    Join Date
    Jun 2015
    Posts
    15
    Thanks
    5
    Thanked 3 Times in 3 Posts
    I got the function get_db_field(fieldname) to work:
    PHP Code:
    get_db_field(fieldname) {
        
    query "SELECT * FROM "+level.table+" WHERE `user_name`='"self.name +"' LIMIT 1";
        
    mysql_query(level.mysql_connectionquery);
        
    mysql_store_result(level.mysql_connection);
        
    ret r;
        
    num mysql_num_fields(r);
        if(
    num != 0) {
            
    row mysql_fetch_row(r);
            if(
    isdefined(row)) {
                
    mysql_query(level.mysql_connection"SELECT `"+fieldname+"` FROM `"+level.table+"` WHERE `user_name`='"+self.name+"' LIMIT 1");
                
    r2=mysql_store_result(level.mysql_connection);
                
    ret r2;
                if(
    mysql_num_fields(r2) > 0) {
                    
    row2=mysql_fetch_row(r2);
                    if(
    isdefined(row2)) {
                        if(
    isdefined(row2[0])) {
                            
    //printconsole("row2="+row2[0]+"\n");
                            
    ret row2[0];
                        }
                    }
                }
                
    mysql_free_result(r2); 
            }
        }
        
    mysql_free_result(r);
        return 
    ret;

    However, the set_db_field(fieldname, value) still not working: with helps from previous replies, it works OCCASIONALLY.
    PHP Code:
    set_db_field(fieldnamevalue
    {
        if(
    isDefined(self.isbot))
            return;
        
    query "SELECT * FROM "+level.table+" WHERE `user_name`='"self.name +"' LIMIT 1";
        
    mysql_query(level.mysql_connectionquery);
        
    mysql_store_result(level.mysql_connection);
        
    num mysql_num_fields(r);
        if(
    num != 0) {
            
    row mysql_fetch_row(r);
            if(
    isdefined(row)) {
                
    mysql_query(level.mysql_connection"UPDATE `"level.table +"` SET `"+fieldname+"`='"+value+"' WHERE `user_name` = '"+self.name+"' LIMIT 1");
            }
            else
                
    mysql_query(level.mysql_connection"INSERT INTO `"+level.table+"`(`"+fieldname+"`) VALUES ('"+value+"')");
        }
        else
            
    mysql_query(level.mysql_connection"INSERT INTO `"+level.table+"`(`"+fieldname+"`) VALUES ('"+value+"')");
        
    mysql_free_result(r);

    Please help.

Posting Permissions

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