Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2. $database_host = 'localhost'; // Database hostname
  3. $database_user = 'root'; // Database username
  4. $database_password = ''; // Database password
  5. $database_name = 'myjoomla'; // Database name
  6. $new_table_prefix = 'zkl_'; // New table prefix
  7. $old_table_prefix = 'jos_'; // Old table prefix (optional)
  8. $test = false; // Test-run (true or false)
  9. // NO NEED TO EDIT BELOW THIS LINE
  10. // Login to the database server
  11. $db = mysql_connect($database_host, $database_user, $database_password) or die('MySQL connect failed');
  12. // Connect to the database
  13. mysql_select_db($database_name) or die('Failed to select database');
  14. // Get a listing of all tables
  15. $query = "SHOW TABLES";
  16. $result = mysql_query($query) or die('SHOW TABLES failed');
  17. // Loop through all tables
  18. while($row = mysql_fetch_array($result)) {
  19. $old_table = $row[0];
  20. // Preliminary check: Is the old table prefix correct?
  21. if(!empty($old_table_prefix) && !preg_match('/^'.$old_table_prefix.'/', $old_table)) {
  22. echo "Table $old_table does not match prefix $old_table_prefix<br/>\n";
  23. continue;
  24. }
  25. // Preliminary check: Is the old table prefix the same as the new one?
  26. if(preg_match('/^'.$new_table_prefix.'/', $old_table)) {
  27. echo "Table $old_table already done<br/>\n";
  28. continue;
  29. }
  30. // Construct the new table prefix
  31. if(!empty($old_table_prefix)) {
  32. $new_table = preg_replace('/^'.$old_table_prefix.'/', $new_table_prefix, $old_table);
  33. } else {
  34. $new_table = $new_table_prefix.$old_table;
  35. }
  36. // Rename the actual table
  37. echo "Renaming $old_table to $new_table<br/>\n";
  38. $query = "RENAME TABLE `$old_table` TO `$new_table`";
  39. mysql_query($query);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement