Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Edit this bit with your details
- $server = "mysql.server.com:port";
- $user = "myuser";
- $pass = "mypass";
- $db = "database"
- $table = "tablename";
- // This bit takes care of the work, no need to change things
- // Set variables
- $users = array();
- $stats = array("Scavenger","Excavation,"Mining","Forgery","Dexterity","Range","Combat","WoodCutting");
- // Read the stats from the files
- foreach ($stats as $stat){
- $lines = file($stat.".exp");
- foreach($lines as $line){
- list($user,$value) = split("=",$line);
- $users[$user][$stat] = $value;
- }
- }
- // Connect to the database server
- $link = mysql_connect($server,$user,$pass);
- if (!$link) {
- die('Could not connect: ' . mysql_error());
- }
- // Build up our query for inserting the values
- $query = "INSERT INTO ".$table." VALUES";
- foreach ($users as $user=>$data){
- $query = $query." ( \"".$user."\"";
- foreach ($data as $stat=>$value){
- $query = $query.", ".$value;
- }
- $query = $query." ),";
- }
- $query = substr($query,0,-1);
- // Select the database
- $myDB = mysql_select_db($db, $link);
- if (!$myDB) {
- die('Could not select database \''.$db.'\': ' . mysql_error());
- }
- // Run our query
- $result = mysql_query($query);
- if (!$result) {
- die('Invalid query: ' . mysql_error());
- }
- // Close the connection
- mysql_close($link);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement