Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // Name of the file
  2.  
  3. $filename="Exported_Database/".$_FILES["file1"]["name"];
  4. // MySQL host
  5. $mysql_host = $_POST['host1'];
  6. // MySQL username
  7. $mysql_username = $_POST['username1'];
  8. // MySQL password
  9. $mysql_password = $_POST['password1'];
  10. // Database name
  11. $mysql_database = $_POST['database_name1'];
  12.  
  13. // Connect to MySQL server
  14. mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
  15. // Select database
  16. mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());
  17.  
  18. // Temporary variable, used to store current query
  19. $templine = '';
  20. // Read in entire file
  21. $lines = file($filename);
  22. // Loop through each line
  23. foreach ($lines as $line)
  24. {
  25. // Skip it if it's a comment
  26. if (substr($line, 0, 2) == '--' || $line == '')
  27. continue;
  28.  
  29. // Add this line to the current segment
  30. $templine .= $line;
  31. // If it has a semicolon at the end, it's the end of the query
  32. if (substr(trim($line), -1, 1) == ';')
  33. {
  34. // Perform the query
  35. mysql_query($templine) or print('Error performing query '<strong>' . $templine . '': ' . mysql_error() . '<br /><br />');
  36. // Reset temp variable to empty
  37. $templine = '';
  38. }
  39. }
  40. echo "<script>alert('Tables imported successfully');</script>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement