From f2e66f88a68fab5d5f2c42ee79efb0a350529f2c Mon Sep 17 00:00:00 2001 From: Jimit Modi Date: Wed, 29 Oct 2014 15:19:52 +0530 Subject: Add dropdown of servers to select server for comparasion instead of copy paste, Dropdown will be available only if config contains more than 1 server details --- index.php | 137 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 54 deletions(-) diff --git a/index.php b/index.php index 6585922..aee2b27 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,12 @@ /** * This provides a user-interface for using the DbDiff class. + * + * More information on this tool can be found at: + * http://joefreeman.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/ + * + * Copyright (C) 2009, Joe Freeman + * Available under http://en.wikipedia.org/wiki/MIT_License */ error_reporting(E_ALL); @@ -16,25 +22,25 @@ require('config.php'); * @return void */ function show_options($dbs_config) { - + echo '

Step 1: Export database schemas

'; - + if (count($dbs_config) > 0) { - + echo '

Select a database configuration from the list below, or select \'Enter details...\'

'; - + echo ''; - + } else { - + echo '

Enter connection details in the form below, or setup a database connection in the config.php file.

'; } - + echo '
0 ? ' style="display:none;"' : '' ) . '>'; echo '
'; echo '
'; @@ -42,14 +48,28 @@ function show_options($dbs_config) { echo '
'; echo '
'; echo '
'; - + echo '

Step 2: Compare schemas

'; - + echo '

Once two database schemas have been exported, paste them here to be compared.

'; - + echo '
'; - echo '
'; - echo '
'; + if (count($dbs_config) < 2) { + echo '
'; + echo '
'; + } else { + echo '
'; + echo '
'; + } + echo '
'; echo '
'; } @@ -70,20 +90,20 @@ function echo_error($error) { * @return void */ function export_schema($config) { - + $result = DbDiff::export($config['config'], $config['name']); - + if ($result == null) { echo_error('Couldn\'t connect to database: ' . mysql_error()); return; } - + $serialized_schema = serialize($result); - + echo '

Exported \'' . $config['name'] . '\'

'; - + echo '

Copy the following schema information and then proceed to step 2.

'; - + echo ''; @@ -101,7 +121,7 @@ function strip_nl($str) { /** * Returns an 's' character if the count is not 1. - * + * * This is useful for adding plurals. * * @return string An 's' character or an empty string @@ -118,24 +138,24 @@ function s($count) { * @return void */ function do_compare($schema1, $schema2) { - + if (empty($schema1) || empty($schema2)) { echo_error('Both schemas must be given.'); return; } - + $unserialized_schema1 = unserialize(strip_nl($schema1)); $unserialized_schema2 = unserialize(strip_nl($schema2)); - + $results = DbDiff::compare($unserialized_schema1, $unserialized_schema2); - + if (count($results) > 0) { - + echo '

Found differences in ' . count($results) . ' table' . s(count($results)) . ':

'; - + echo ''; - + } else { echo '

No differences found.

'; } @@ -157,14 +177,14 @@ function do_compare($schema1, $schema2) { DbDiff - + - + - +
- +

DbDiff

Tool for comparing database schemas.

@@ -173,29 +193,29 @@ function do_compare($schema1, $schema2) { $action = @$_GET['a']; switch ($action) { - + case 'export_schema': - + if (isset($_GET['db'])) { - + $db = $_GET['db']; - + if (!isset($dbs_config[$db])) { echo_error('No database configuration selected.'); break; } $config = $dbs_config[$db]; - + } else { - + if (!isset($_POST['db-host']) || !isset($_POST['db-user']) || !isset($_POST['db-password']) || !isset($_POST['db-name'])) { echo_error('No database configuration entered.'); break; } - + $config = array( 'name' => $_POST['db-name'] . ' (' . $_POST['db-host'] . ')', 'config' => array( @@ -206,41 +226,50 @@ switch ($action) { ) ); } - + export_schema($config); - + echo '

« Back to main page

'; - + break; - + case 'compare': + + if (count($dbs_config) < 2) { + $schema1 = @$_POST['schema1']; + $schema2 = @$_POST['schema2']; + + if (get_magic_quotes_gpc()) { // sigh... + $schema1 = stripslashes($schema1); + $schema2 = stripslashes($schema2); + } + } else { + $schema1 = $dbs_config[@$_POST['schema1']]; + $schema2 = $dbs_config[@$_POST['schema2']]; - $schema1 = @$_POST['schema1']; - $schema2 = @$_POST['schema2']; - - if (get_magic_quotes_gpc()) { // sigh... - $schema1 = stripslashes($schema1); - $schema2 = stripslashes($schema2); + $schema1 = serialize(DbDiff::export($schema1['config'], $schema1['name'])); + $schema2 = serialize(DbDiff::export($schema2['config'], $schema2['name'])); } do_compare($schema1, $schema2); - + echo '

« Back to main page

'; - + break; - + default: - + show_options($dbs_config); } ?>
- + \ No newline at end of file -- cgit v1.1