Skip to content

Instantly share code, notes, and snippets.

@Awzaw
Created December 16, 2016 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Awzaw/af23b3a13f26c3a398f4e96bfa8daaf8 to your computer and use it in GitHub Desktop.
Save Awzaw/af23b3a13f26c3a398f4e96bfa8daaf8 to your computer and use it in GitHub Desktop.
Import SimpleAuth YAML to MySQL
<?php
//Set Paths
$hostname = "localhost";
$username = "DB_USER";
$password = "DB_PASSWORD";
$dbname = "DB_NAME";
$usertable = "simpleauth_players";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);
set_include_path(get_include_path() . PATH_SEPARATOR . '/PATH_TO_SPYC');
require_once ('Spyc.php');
$di = new RecursiveDirectoryIterator('/SERVER_PATH/plugins/SimpleAuth/players/');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
$playeryml = $file->getRealPath();
$player = basename($playeryml, ".yml");
$firstletter = substr($player, 0, 1);
$Data = Spyc::YAMLLoad($playeryml);
$hash = $Data["hash"];
$registerdate = $Data["registerdate"];
$logindate = $Data["logindate"];
$lastip = $Data["lastip"];
$query = "INSERT INTO simpleauth_players (name, hash, registerdate, logindate) VALUES ('" . $player . "', '" . $hash . "', '" . $registerdate . "', '" . $logindate . "')";
$result = mysql_query($query);
if ($result) {
echo "New record created for " . $player . "\n";
} else {
echo "Error: " . $query . "\n" . $connection->error;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment