Created
December 16, 2016 23:10
-
-
Save Awzaw/af23b3a13f26c3a398f4e96bfa8daaf8 to your computer and use it in GitHub Desktop.
Import SimpleAuth YAML to MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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