View Single Post
C00ller
Junior Member
Join Date: Sep 2007
Old 08-23-2014 , 10:31   Re: Fix SteamIDs for the new update
Reply With Quote #13

Another solution: update old SteamIDs to new format right in the database.

I wrote PHP-script to update old SteamIDs to new ones (in order to use that change $DB* vars accordingly) for TF2-related stats:

Code:
<?php

// RUN ONLY ONCE!!! Or restore from backup before any extra run!

$DBServ = "localhost";
$DBUser = "root";
$DBPass = "";
$DBName = "hlstats";
$DBTable = "hlstats_PlayerUniqueIds";

$db = mysql_connect($DBServ, $DBUser, $DBPass) or die("Can't connect to MySQL server");
mysql_select_db($DBName) or die("Can't select DB");

$now = time();

mysql_query("CREATE TABLE " . $DBTable . "_copy_" . $now . " LIKE $DBTable");
mysql_query("INSERT " . $DBTable . "_copy_" . $now . " SELECT * FROM $DBTable");

mysql_query("DELETE FROM $DBTable WHERE game = 'tf' AND INSTR(uniqueId, 'U') > 0");
mysql_query("UPDATE $DBTable SET uniqueId=CONCAT('[U:1:', SUBSTR(uniqueId, 1, 1)+SUBSTR(uniqueId, 3)*2, ']') WHERE game = 'tf'");

// Redundant code :)
/*
$players = mysql_query("SELECT * FROM $DBTable");
while($row = mysql_fetch_assoc($players))
{
    $id = $row["playerId"];
    $oldsteamid = $row["uniqueId"];

    $idparts = explode(':', $oldsteamid);
    $newsteamid = "[U:1:" . ($idparts[1] * 2 + $idparts[0]) . "]";
    mysql_query("UPDATE $DBTable SET game='$oldsteamid', uniqueId = '$newsteamid' WHERE playerId = $id");
}

mysql_free_result($players);
*/

mysql_close($db);

echo "Done";
Script does the backup copy of used table and deletes player records with new IDs (to prevent uniqueId duplicating after update).

Last edited by C00ller; 08-23-2014 at 18:00. Reason: game dependance added, redudant cycle replaced
C00ller is offline