Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2. // Edit this bit with your details
  3. $server = "mysql.server.com:port";
  4. $user = "myuser";
  5. $pass = "mypass";
  6. $table = "tablename";
  7.  
  8. // This bit takes care of the work, no need to change things
  9. // Set variables
  10. $users = array();
  11. $stats = array("Scavenger","Excavation,"Mining","Forgery","Dexterity","Range","Combat","WoodCutting");
  12.  
  13. // Read the stats from the files
  14. foreach ($stats as $stat){
  15. $lines = file($stat.".exp");
  16. foreach($lines as $line){
  17. list($user,$value) = split("=",$line);
  18. $users[$user][$stat] = $value;
  19. }
  20. }
  21.  
  22. // Connect to the database
  23. $link = mysql_connect($server,$user,$pass);
  24. if (!$link) {
  25. die('Could not connect: ' . mysql_error());
  26. }
  27.  
  28. // Build up our query for inserting the values
  29. $query = "INSERT INTO ".$table." VALUES";
  30. foreach ($users as $user=>$data){
  31. $query = $query." ( \"".$user."\"";
  32. foreach ($data as $stat=>$value){
  33. $query = $query.", ".$value;
  34. }
  35. $query = $query." ),";
  36. }
  37. $query = substr($query,0,-1);
  38.  
  39. // Run our query
  40. $result = mysql_query($query);
  41. if (!$result) {
  42. die('Invalid query: ' . mysql_error());
  43. }
  44.  
  45. // Close the connection
  46. mysql_close($link);
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement