Advertisement
Guest User

Untitled

a guest
Aug 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. // Name of the file
  4. $filename = 'churc.sql';
  5. // MySQL host
  6. $mysql_host = 'localhost';
  7. // MySQL username
  8. $mysql_username = 'root';
  9. // MySQL password
  10. $mysql_password = '';
  11. // Database name
  12. $mysql_database = 'dump';
  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. continue;
  29.  
  30. // Add this line to the current segment
  31. $templine .= $line;
  32. // If it has a semicolon at the end, it's the end of the query
  33. if (substr(trim($line), -1, 1) == ';')
  34. {
  35. // Perform the query
  36. mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
  37. // Reset temp variable to empty
  38. $templine = '';
  39. }
  40. }
  41. echo "Tables imported successfully";
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement