Xt3mP

CMSPwner v1.5 SQLDump Module

Aug 10th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2. #########
  3. # Script Title: CMSPwner v1.5 SQLDump module
  4. # Version: 1.5 Beta
  5. # Date: 10/08/12
  6. # Script Author: Xt3mP
  7. # Home: http://xt3mp.mx
  8. # For: http://r00tw0rm.com
  9. # Contact: xt3mp[at]null[dot]com
  10. #  _____ _____ _____ _____                  
  11. # |     |     |   __|  _  |_ _ _ ___ ___ ___
  12. # |   --| | | |__   |   __| | | |   | -_|  _|
  13. # |_____|_|_|_|_____|__|  |_____|_|_|___|_|  
  14. #
  15. #########
  16. $server = 'localhost';
  17. $user = 'root';
  18. $pass = '';
  19. $db = 'wpwp';
  20. $pref = 'wp_';
  21. $dumpFile = 'dump.sql';
  22.  
  23. $con = mysql_connect($server, $user, $pass);
  24. @mysql_select_db($db, $con);
  25. $tables = @mysql_query('SHOW TABLES');
  26.  
  27. while($table = @mysql_fetch_object($tables))
  28. {
  29.     if(substr($table->{'Tables_in_'.$db}, 0, strlen($pref)) == $pref)
  30.         $cmsTables[] = $table->{'Tables_in_' . $db};
  31. }
  32.  
  33. $dumpSQL = '--' . "\n" . '-- Generated by: CMSPwner v1.5' . "\n".'-- Author: Xt3mP' . "\n" . '-- Website: http://xt3mp.mx' . "\n" . '-- Database: ' . $db . "\n" . '-- Tables: ' . count($cmsTables) . "\n" . '-- ' . "\n\n";
  34.  
  35. foreach($cmsTables as $table)
  36. {
  37.     $tableQuery = @mysql_query('SELECT * FROM '.$table);
  38.     $dumpSQL .= '--' . "\n" . '-- Table: ' . $table . "\n" . '--' . "\n\n";
  39.     $dumpSQL .= 'DROP TABLE IF EXISTS `' . $table . "`;\n\n";
  40.     $tableNumFields = @mysql_num_fields($tableQuery);
  41.  
  42.     if($tableNumFields > 0)
  43.     {
  44.         $tableStructure = @mysql_fetch_object(mysql_query('SHOW CREATE TABLE ' . $table));
  45.         $dumpSQL .= $tableStructure->{'Create Table'} . ";\n\n";
  46.  
  47.         for($numField = 0; $numField < $tableNumFields; $numField++)
  48.         {
  49.             while($fields = @mysql_fetch_row($tableQuery))
  50.             {
  51.                 $dumpSQL .= 'INSERT INTO ' . $table . ' VALUES (';
  52.  
  53.                 for($idField = 0; $idField < $tableNumFields; $idField++)
  54.                 {
  55.                     $fieldData = addslashes($fields[$idField]);
  56.  
  57.                     if(!empty($fieldData))
  58.                         $dumpSQL .= (is_numeric($fieldData)) ? $fieldData . ', ' : '"' . $fieldData . '" ,';
  59.                     else
  60.                         $dumpSQL .= '"", ';
  61.                 }
  62.  
  63.                 $dumpSQL = substr($dumpSQL, 0, strlen($dumpSQL) - 2);
  64.                 $dumpSQL .= ');' . "\n";
  65.             }
  66.         }
  67.  
  68.         $dumpSQL .= "\n";
  69.     }
  70. }
  71.  
  72. $file = fopen($dumpFile, 'w+');
  73. fwrite($file, $dumpSQL);
  74. fclose($file);
  75. ?>
Add Comment
Please, Sign In to add comment