'; } // Check whether one of the submit button was pressed if (isset($_POST['saveBtn']) || isset($_POST['dispBtn'])){ // Set the variables from the user input $host = isset($_POST['hostname'])? $_POST['hostname'] : 'localhost'; $user = isset($_POST['username'])? $_POST['username'] : ''; $pass = isset($_POST['password'])? $_POST['password'] : ''; $port = isset($_POST['port']) ? $_POST['port'] : '3306'; $out = ''; $outfile= ''; $fullhost = $host.":".$port; // Make a MySQL connection $link = mysql_connect($fullhost,$user,$pass); // Check if connection was success if (!$link){ echo '
Can not connect to database: '.mysql_error().'
'; die; } // Get all databases $dbs = mysql_query('SHOW DATABASES'); $outfile.=''."\n"; $out .= htmlspecialchars(''."\n"); while ($dbrow = mysql_fetch_array($dbs, MYSQL_NUM)) { $db = $dbrow[0]; mysql_selectdb($db,$link); $result = mysql_query('SHOW TABLES'); $outfile.=" \n"; $out.="   "; $out.=htmlspecialchars("\n"); // Get all tables for the actual database while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $table = $row[0] ; $struct = mysql_query('DESCRIBE '.$table); $outfile.=' '."\n"; $out.="      "; $out.= htmlspecialchars('
'."\n"); // Get all fields for the actual table while ($row2 = mysql_fetch_array($struct, MYSQL_NUM)) { $autoi = (strstr($row2[5],'auto_increment')) ? 'YES' : 'NO'; $tmp =' '."\n"; $outfile.=$tmp; $out.="         "; $out.=htmlspecialchars($tmp); } // Close table element $outfile.='
'."\n"; $out.="      "; $out.=htmlspecialchars(''."\n"); } // Close database element $outfile.="
\n"; $out.="   "; $out.=htmlspecialchars("
\n"); } // Close the server element $outfile.='
'; $out.=htmlspecialchars('
'); // Check output format and display or save the result if (isset($_POST['dispBtn'])){ writeHeader(); echo '
'; echo nl2br($out) ; echo '
'; } else{ // Save output as file $filecontent=$outfile; $downloadfile='MySQL_Server.xml'; header("HTTP/1.1 200 OK"); header("Content-Length: ".strlen($filecontent)); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=$downloadfile"); header("Content-Transfer-Encoding: binary"); echo $filecontent; } } // Display the form for the user else { writeHeader(); ?>
Database connection informations
Hostname:
Username:
Password:
Port: