Guest User

Untitled

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