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 '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '

Step 2: Compare schemas

'; echo '

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

'; echo '
'; if (count($dbs_config) < 2) { echo '
'; echo '
'; } else { echo '
'; echo '
'; } echo '
'; echo '
'; } /** * Convenience method for outputting errors. * * @return void **/ function echo_error($error) { echo '

', $error, '

'; } /** * Export the schema from the database specified and echo the results. * * @param string $db The key of the config to be extracted from $dbs_config. * @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 ''; } /** * Strips new line characters (CR and LF) from a string. * * @param string $str The string to process. * @return string The string without CRs or LFs. */ function strip_nl($str) { return str_replace(array("\n", "\r"), '', $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 **/ function s($count) { return $count != 1 ? 's' : ''; } /** * Compare the two schemas and echo the results. * * @param string $schema1 The first schema (serialized). * @param string $schema2 The second schema (serialized). * @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.

'; } } ?> DbDiff

DbDiff

Tool for comparing database schemas.

$_POST['db-name'] . ' (' . $_POST['db-host'] . ')', 'config' => array( 'host' => $_POST['db-host'], 'user' => $_POST['db-user'], 'password' => $_POST['db-password'], 'name' => $_POST['db-name'] ) ); } 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 = 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); } ?>