Advertisement
Guest User

Untitled

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