×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Jing Tai Piao
Added: Apr 18, 2013 1:29 AM
Views: 34
Tags: no tags
  1. hp
  2.  
  3. // your prefix here
  4. $prefix = 'mage1610_';
  5.  
  6. // magento sample data file
  7. $dumpFile = "magento-sample-data-1.6.1.0/magento_sample_data_for_1.6.1.0.sql";
  8.  
  9. // new sample data file
  10. $outFile = "new-sample-data.sql";
  11.  
  12. $search = array("TABLES `", "TABLE `", "EXISTS `", "INTO `", "REFERENCES `");
  13. $replace = array("TABLES `$prefix", "TABLE `$prefix", "EXISTS `$prefix", "INTO `$prefix", "REFERENCES `$prefix");
  14.  
  15. $file = file_get_contents($dumpFile);
  16.  
  17. if ($file !== FALSE) {
  18. $file = str_ireplace($search, $replace, $file);
  19. if (file_put_contents($outFile,$file) !== FALSE) {
  20. echo "Successfully written new sample data dump to $outFile.\n";
  21. } else {
  22. echo "Error writing new sample data dump.\n";
  23. }
  24. } else {
  25. echo "Error reading dump file.\n";
  26. }
  27.  
  28. ?>