Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. < ?php
  2. /*
  3. * Restore MySQL dump using PHP
  4. * (c) 2006 Daniel15
  5. * Last Update: 9th December 2006
  6. * Version: 0.2
  7. * Edited: Cleaned up the code a bit.
  8. *
  9. * Please feel free to use any part of this, but please give me some credit :-)
  10. */
  11.  
  12. // Name of the file
  13. $filename = 'test.sql';
  14. // MySQL host
  15. $mysql_host = 'localhost';
  16. // MySQL username
  17. $mysql_username = 'root';
  18. // MySQL password
  19. $mysql_password = '';
  20. // Database name
  21. $mysql_database = 'test';
  22.  
  23. //////////////////////////////////////////////////////////////////////////////////////////////
  24.  
  25. // Connect to MySQL server
  26. mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
  27. // Select database
  28. mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());
  29.  
  30. // Temporary variable, used to store current query
  31. $templine = '';
  32. // Read in entire file
  33. $lines = file($filename);
  34. // Loop through each line
  35. foreach ($lines as $line)
  36. {
  37. // Skip it if it's a comment
  38. if (substr($line, 0, 2) == '--' || $line == '')
  39. continue;
  40.  
  41. // Add this line to the current segment
  42. $templine .= $line;
  43. // If it has a semicolon at the end, it's the end of the query
  44. if (substr(trim($line), -1, 1) == ';')
  45. {
  46. // Perform the query
  47. mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
  48. // Reset temp variable to empty
  49. $templine = '';
  50. }
  51. }
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement