summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Freeman <joe.freeman@bitroot.com>2014-10-29 13:30:31 +0100
committerJoe Freeman <joe.freeman@bitroot.com>2014-10-29 13:30:31 +0100
commitb39bea618380dbe74b6516d189f92206a9789451 (patch)
treec6e6f04e21502aee1c937ddf415cd9d28fe37e26
parent14d6a4960ae34905a7a952480e735fc103777a25 (diff)
parentc8b9a477f12ccdc1cd757f8affc8453a3d4c7487 (diff)
downloaddbdiff-b39bea618380dbe74b6516d189f92206a9789451.zip
dbdiff-b39bea618380dbe74b6516d189f92206a9789451.tar.gz
dbdiff-b39bea618380dbe74b6516d189f92206a9789451.tar.bz2
Merge pull request #1 from jimymodi/master
Dropdown for Servers
-rw-r--r--.gitignore9
-rw-r--r--config.php.dist (renamed from config.php)0
-rw-r--r--index.php131
3 files changed, 86 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..401c72a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+config.php
+nbproject*
+.buildpath
+.project
+.settings
+.settings/
+/*.bak
+/*~
+mailoutput*
diff --git a/config.php b/config.php.dist
index d5ff315..d5ff315 100644
--- a/config.php
+++ b/config.php.dist
diff --git a/index.php b/index.php
index 6585922..4e6f159 100644
--- a/index.php
+++ b/index.php
@@ -2,6 +2,7 @@
/**
* This provides a user-interface for using the DbDiff class.
+ *
*/
error_reporting(E_ALL);
@@ -16,25 +17,25 @@ require('config.php');
* @return void
*/
function show_options($dbs_config) {
-
+
echo '<h3>Step 1: Export database schemas</h3>';
-
+
if (count($dbs_config) > 0) {
-
+
echo '<p class="info">Select a database configuration from the list below, or select \'Enter details...\'</p>';
-
+
echo '<ul id="db-list">';
foreach ($dbs_config as $key => $db_config) {
echo '<li><a href="?a=export_schema&db=' . $key . '">' . $db_config['name'] . '</a></li>';
}
echo '<li><em><a href="#" onclick="document.getElementById(\'db-config\').style.display=\'block\';return false;">Enter details...</a></em></li>';
echo '</ul>';
-
+
} else {
-
+
echo '<p class="info">Enter connection details in the form below, or setup a database connection in the <code>config.php</code> file.</p>';
}
-
+
echo '<form action="?a=export_schema" method="post" id="db-config"' . (count($dbs_config) > 0 ? ' style="display:none;"' : '' ) . '>';
echo '<div class="field"><label for="db-host">Host</label><input type="text" name="db-host" id="db-host" value="localhost" /></div>';
echo '<div class="field"><label for="db-user">User</label><input type="text" name="db-user" id="db-user" /></div>';
@@ -42,14 +43,28 @@ function show_options($dbs_config) {
echo '<div class="field"><label for="db-name">Database</label><input type="text" name="db-name" id="db-name" /></div>';
echo '<div class="submit"><input type="submit" value="Export" /></div><div class="clearer"></div>';
echo '</form>';
-
+
echo '<h3>Step 2: Compare schemas</h3>';
-
+
echo '<p class="info">Once two database schemas have been exported, paste them here to be compared.</p>';
-
+
echo '<form action="?a=compare" method="post" id="compare">';
- echo '<div class="field"><label for="schema1">First schema</label><textarea name="schema1" id="schema1" cols="100" rows="5"></textarea></div>';
- echo '<div class="field"><label for="schema2">Second schema</label><textarea name="schema2" id="schema2" cols="100" rows="5"></textarea></div>';
+ if (count($dbs_config) < 2) {
+ echo '<div class="field"><label for="schema1">First schema</label><textarea name="schema1" id="schema1" cols="100" rows="5"></textarea></div>';
+ echo '<div class="field"><label for="schema2">Second schema</label><textarea name="schema2" id="schema2" cols="100" rows="5"></textarea></div>';
+ } else {
+ echo '<div class=""><label for="schema1">First schema</label><select name="schema1">';
+ foreach ($dbs_config as $key => $db_config) {
+ echo '<option value='. $key .'>' . $db_config['name'] . '</option>';
+ }
+ echo '</select></div>';
+ echo '<div class=""><label for="schema2">Second schema</label><select name="schema2">';
+ foreach ($dbs_config as $key => $db_config) {
+ echo '<option value='. $key .'>' . $db_config['name'] . '</option>';
+ }
+ echo '</select></div>';
+ }
+
echo '<div class="submit"><input type="submit" value="Compare" /></div>';
echo '</form>';
}
@@ -70,20 +85,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 '<h3>Exported \'' . $config['name'] . '\'</h3>';
-
+
echo '<p>Copy the following schema information and then proceed to <a href="?">step 2</a>.</p>';
-
+
echo '<textarea cols="100" rows="20" onclick="this.focus();this.select();">';
echo chunk_split($serialized_schema, 100);
echo '</textarea>';
@@ -101,7 +116,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 +133,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 '<h3>Found differences in ' . count($results) . ' table' . s(count($results)) . ':</h3>';
-
+
echo '<ul id="differences">';
foreach ($results as $table_name => $differences) {
-
+
echo '<li><strong>' . $table_name . '</strong><ul>';
foreach ($differences as $difference) {
echo '<li>' . $difference . '</li>';
@@ -143,7 +158,7 @@ function do_compare($schema1, $schema2) {
echo '</ul></li>';
}
echo '</ul>';
-
+
} else {
echo '<p>No differences found.</p>';
}
@@ -157,14 +172,14 @@ function do_compare($schema1, $schema2) {
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DbDiff</title>
-
+
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
-
+
</head>
<body>
-
+
<div id="canvas">
-
+
<h1><a href="?">DbDiff</a></h1>
<h2>Tool for comparing database schemas.</h2>
@@ -173,29 +188,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 +221,49 @@ switch ($action) {
)
);
}
-
+
export_schema($config);
-
+
echo '<p><a href="?">&laquo; Back to main page</a></p>';
-
+
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 '<p><a href="?">&laquo; Back to main page</a></p>';
-
+
break;
-
+
default:
-
+
show_options($dbs_config);
}
?>
<div id="footer">
- <p>More information on this tool is available from the corresponding <a href="http://joef.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/">blog post</a>.</p>
+ <p>More information on this tool is available from the corresponding <a href="http://joefreeman.co.uk/blog/2009/07/php-script-to-compare-mysql-database-schemas/">blog post</a>.</p>
</div>
</div>
</body>
-</html>
+</html> \ No newline at end of file