Results 1 to 3 of 3

Thread: Setup mysql + cod2

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    Setup mysql + cod2

    Hi all,

    I used the save the stats on a loginname with scriptdata, but I want to change to the use of mysql. But I dont know much about it.
    How to start? Do I have to setup a database first (Like for B3)?

    Then Kung posted this script
    Code:
    mysql_test()
    {
        host = getcvar("mysql_host");
        user = getcvar("mysql_user");
        pass = getcvar("mysql_pass");
        db = getcvar("mysql_db");
        port = getcvarint("mysql_port");
        
        
        mysql = mysql_init();
        
        if ( ! isDefined(mysql))
        {
            printfline("mysql not defined!");
            return;    
        }
    
         printfline("mysql=" + ("2"+2) + "\n");
        
        ret = mysql_real_connect(mysql, host, user, pass, db, port);
        if (!ret)
        {
            printfline("errno="+mysql_errno(mysql) + " error=''"+mysql_error(mysql) + "''\n");
            mysql_close(mysql);
            return 0;
        }
        
         printfline("affected_rows="+mysql_affected_rows(mysql)+"\n");
        
        
        
        name = "fo\"0'z0`r"; // all user-input is evil!
        name = mysql_real_escape_string(mysql, name); // so escape it :)
        
        theQuery = "SELECT * FROM players";
        theQuery = "SELECT \""+name+"\" as first,2 as second,3 as third UNION SELECT 11,22,33";
        
       printfline(theQuery);
        
        ret = mysql_query(mysql, theQuery);
        if (ret != 0)
        {
            printfline("errno="+mysql_errno(mysql) + " error=''"+mysql_error(mysql) + "''\n");
            mysql_close(mysql);
            return 0;
        }
        
        result = mysql_store_result(mysql);
        
        printfline("num_rows="+mysql_num_rows(result) + " num_fields="+mysql_num_fields(result)+"\n");
        
        mysql_field_seek(result, 0);
        while (1)
        {
            result_name = mysql_fetch_field(result);
            if (!isString(result_name))
                break;
           printfline("field-name=" + result_name+"\n");
        }
        
        while (1)
        {
            row = mysql_fetch_row(result);
            if (!isDefined(row))
            {
                printfline("row == undefined\n");
                break;
            }
            output = "";
            for (i=0; i<row.size; i++)
                output += row[i] + " ";
             printfline(output+"\n");
        }
        
        mysql_free_result(result);
        
        mysql_close(mysql);
                
    }
    So how is that Database build? For example I call a database with the name "players".
    The first thing I want to see is the loginname, followed by password and then the kills.
    How can I save it like that?
    And how can I load it?
    And what if the name already exist?

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    The query to create the table is in cod2_std/persistence.gsc: https://github.com/kungfooman/cod2_s...ersistence.gsc

    Connect with HeidiSQL to your MySQL server and just execute the CREATE TABLE query etc. to get a feel what those queries in persistence.gsc do: http://www.heidisql.com/
    timescale 0.01

  3. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (2nd March 2016)

  4. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  5. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (2nd March 2016)

Posting Permissions

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