Results 1 to 4 of 4

Thread: No clue on how to implement MySQL integration...

  1. #1
    Private
    Join Date
    Nov 2014
    Posts
    25
    Thanks
    9
    Thanked 3 Times in 2 Posts

    No clue on how to implement MySQL integration...

    Can anyone point me in the right direction to connecting to MySQL then reading tables, columns and rows?
    Already got MySQL setup with a database, example tables, columns and rows...
    Last edited by Kemi; 13th November 2015 at 16:08.

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    I'm using this:
    PHP Code:
        level.mysql mysql_reuse_connection();
        if(!
    isdefined(level.mysql))
        {
            
    make_global_mysql(hostuserpassdbport);
        }
        
    level.mysql_wrapper = ::mysql_wrapper
    and this as helper:
    PHP Code:

    mysql_wrapper
    (querysaveResults)
    {
        if(!
    isDefined(saveResults))
            
    saveResults false;
        
    mysql level.mysql;
        if(!
    isDefined(mysql))
            return 
    undefined;
        if(
    getcvarint("show_mysql") == 1)
            
    printf("mysql_query:" query "\n");
        
    result mysql_query(mysqlquery);
        
    resettimeout();
        if(
    result)
            return 
    undefined;
        if(
    saveResults)
            return 
    mysql_store_result(mysql);
        return 
    undefined;
    }

    make_global_mysql(hostuserpassdbport)
    {    
        
    mysql mysql_init();
        
    ret mysql_real_connect(mysqlhostuserpassdbport);
        if(!
    ret)
        {
            
    printf("errno=" mysql_errno(mysql) + " error= " mysql_error(mysql) + "\n");
            
    mysql_close(mysql);
            return;
        }
        
    level.mysql mysql;
    }

    stripstring(string)
    {
        return 
    mysql_real_escape_string(level.mysqlstring);

    Then I can just:
    PHP Code:
        result = [[level.mysql_wrapper]]("SELECT mapid FROM mapids WHERE mapname = '" stripstring(mapname) + "'"true);
        if(
    isdefined(result))
        {
            if(
    mysql_num_rows(result))
            {
                
    row mysql_fetch_row(result);
                
    level.mapid int(row[0]);
            }
            
    mysql_free_result(result);
        } 
    Last edited by IzNoGoD; 13th November 2015 at 16:23.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    Kemi (10th May 2017),kung foo man (13th November 2015)

  4. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Follow-up:

    1) test your queries
    2) debug your queries
    3) never trust anything the user can input, always escape it properly
    4) always mysql_free_result(result) if result is defined
    5) never free_result twice on the same result.
    6) mysql will add laggs when your queries take longer than 0.05 seconds, use async mysql then (see some other thread)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  5. #4
    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
    Well, either libcod:

    As example you can use this: https://github.com/kungfooman/cod2_s...bugging.gsc#L4

    Or some primitive "communication" via the log files/rcon, as B3 does it.
    timescale 0.01

Posting Permissions

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