Ni3ls
6th May 2019, 16:53
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:
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
define('COLUMN_DELIMETER', ',');
$mysqli = new mysqli(MYSQL_HOST, MYSQL_DBUSER, MYSQL_DBPASS, MYSQL_DBNAME, MYSQL_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_DELIMETER, fgets($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);
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:
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
define('COLUMN_DELIMETER', ',');
$mysqli = new mysqli(MYSQL_HOST, MYSQL_DBUSER, MYSQL_DBPASS, MYSQL_DBNAME, MYSQL_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_DELIMETER, fgets($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);