Results 1 to 5 of 5

Thread: Convert playerstats from scriptdata to mysql table

Threaded View

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

    Convert playerstats from scriptdata to mysql table

    I have 80K small .txt files with data which i want to convert to a sql table.

    The files in the folder look like this: player_123.txt 123 can be any number but must also be stored in the table as guid

    All .txt files have the same layout:
    Code:
    27,1,3,TU VIRGINIDAD,
    27 is number of kills 1 is number of headshots 3 is number of bashes TU VIRGINIDAD is the name

    My questions :
    1. How can you retrieve info from the filename? The $guid in the code below.
    2. And how to convert it correctly? I get only zeros now

    PHP Code:
    <?php

    define
    ('COLUMN_DELIMETER'',');

    $mysqli = new mysqli(MYSQL_HOSTMYSQL_DBUSERMYSQL_DBPASSMYSQL_DBNAMEMYSQL_DBPORT);

    if (
    $mysqli->connect_errno) {
        
    printf("Connect failed: %s\n"$mysqli->connect_error);
        exit();
    }


        
    $files scandir('/home/.callofduty2/sd2/scriptdata/stats');
        foreach(
    $files as $file) {

        
    $result explode(COLUMN_DELIMETERfgets($file));

        
    $kills = (int)$result[0];
        
    $headshots = (int)$result[1];
        
    $bash = (int)$result[2];
        
    $name = (string)mysqli_real_escape_string($mysqli$result[3]);
        
    $guid code to get guid from txt file;

        
    $sql "INSERT INTO stats (name, kills, headshot, bash, guid) VALUES ('$name', $kills$headshots$bash$guid)";
        
    $mysqli->query($sql);

    }

    fclose($file);

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

    kung foo man (7th May 2019)

Posting Permissions

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