Ok, it is done. Here is a link to the file:
SaveMyDB.php.rarIn case you can't get the file, here is the code:
CODE
<html>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=UTF-8'>
<title>Save My DATABASE</title>
<meta name='author' content='Dorin Grigore' />
</head>
<body>
<?php
echo "<center><table style='border: 1px solid black; background-color: #e3e3e3;'><tr><td>";
if ( $_POST && $_POST['delete_file'] == "go_ahead" )
{
mysql_connect( "$_POST[hostname]", "$_POST[username]", "$_POST[password]") or die(mysql_error());
unlink( $_POST['filename_to_delete'] );
echo "<font size='4' color='green'>File deleted successfully from server.</font>";
}
else if ( $_POST && $_POST['selected_db'] )
{
mysql_connect( "$_POST[hostname]", "$_POST[username]", "$_POST[password]") or die(mysql_error());
mysql_select_db( "$_POST[selected_db]" ) or die(mysql_error());
echo "<i>Database <b>$_POST[selected_db]</b> selected successfully.<br /><br />";
$myfile = fopen( "$_POST[filename]", 'w') or die("If you want to set permissions, check about CHMOD.");
echo "File <b>$_POST[filename]</b> created successfully.<br /><br />";
// Let's start writing to our newly created file
$mybigstring = "-- ----------------------\n";
$mybigstring .= "-- dumped base $_POST[selected_db] at ".date("d-M-Y")."\n";
$mybigstring .= "-- ----------------------\n\n\n";
// Get the list of tables and loop for each
$query = mysql_query( "SHOW TABLES" ) or die( mysql_error() );
while ( $row = mysql_fetch_row( $query ) )
{
$mybigstring .= "-- ----------------------\n";
$mybigstring .= "-- Creation of table $row[0]\n";
$mybigstring .= "-- ----------------------\n";
// Here we write the creation process of the table (it's structure)
$query2 = mysql_query( "SHOW CREATE TABLE $row[0]" );
while( $row2 = mysql_fetch_row( $query2 ) )
{
$mybigstring .= $row2[1].";\n\n";
}
// And here, we write the content of the table (insert into)
$tabledata = mysql_query( "SELECT * FROM $row[0]" ) or die( mysql_error() );
while ( $row_tabledata = mysql_fetch_row( $tabledata ) )
{
$mybigstring .= "INSERT INTO $row[0] VALUES (";
for ( $i = 0; $i < mysql_num_fields( $tabledata ); ++$i )
{
if( $i != 0 ) $mybigstring .= ", ";
$mybigstring .= "'";
$mybigstring .= addslashes( $row_tabledata[ $i ] );
$mybigstring .= "'";
}
$mybigstring .= ");\n\n";
}
}
// disconnect from MySQL
mysql_close();
fwrite( $myfile, $mybigstring );
fclose( $myfile );
echo "<form action='' method='post' name='frm' id='frm'>
Here is the link to download the exported file:<br /><a target='_blank' href='$_POST[filename]'>$_POST[filename]</a><br />(<small>Right click on the link and select 'Save as'.</small>)<br /><br /><br /><font size='4' color='red'>After you downloaded the file,<br />please click <input type='submit' value='here'> to delete-it from server!</font>
<input type='hidden' value='$_POST[hostname]' name='hostname'>
<input type='hidden' value='$_POST[username]' name='username'>
<input type='hidden' value='$_POST[password]' name='password'>
<input type='hidden' value='$_POST[filename]' name='filename_to_delete'>
<input type='hidden' value='go_ahead' name='delete_file'>
</form>";
}
else if ( $_POST )
{
if ( $_POST['filename'] && !$_POST['selected_db'] ) echo "<font color='red'>Please select a database.</font><br /><br />";
mysql_connect( "$_POST[hostname]", "$_POST[username]", "$_POST[password]") or die(mysql_error());
echo "<i>Connected successfully.</i><br /><br />Here are your databases,<br />please select one:<br /><br />";
$query = mysql_query( "SHOW DATABASES" ) or die (mysql_error());
echo "<form action='' method='post' name='frm' id='frm'>
<table style='border: 1px solid blue; background-color: #22e2e2; width: 100%;'><tr><td>
<input type='hidden' value='$_POST[hostname]' name='hostname'>
<input type='hidden' value='$_POST[username]' name='username'>
<input type='hidden' value='$_POST[password]' name='password'>";
while ( $row = mysql_fetch_array( $query ) )
{
echo "<input type='radio' name='selected_db' value='$row[0]'> $row[0]<hr />";
}
$rand_name = rand(1,99999);
//$rand_name .= md5(time());
$rand_name .= rand(1,99999);
echo "</td></tr></table><br /><br />
Please insert the name of the file in which you want to export:<br /><i><small>Note: The file will be saved in the same folder where this .php file is.<br />To save in a different folder, insert like this: <b>folder/anotherfolder/$rand_name.sql</b><br /><font color='red'>Also, make sure no one knows about this place.</font></small></i>
<input style='width: 100%' type='text' value='$rand_name.sql' name='filename'><br /><i><small>You need permissions to the folder to create the exported file.</small></i><br />
<input style='width: 100%' type='submit' value='Continue'>
</form>";
}
else
{
echo "<form action='' method='post' name='frm' id='frm'>
<table>
<i>Welcome to your database saver</i><br /><br />
<tr> <td style='border: 1px solid white;'>Hostname</td> <td style='width: 100%'><input type='text' name='hostname' value='localhost'></td> </tr>
<tr> <td style='border: 1px solid white;'>Username</td> <td><input type='text' name='username' value='root'></td> </tr>
<tr> <td style='border: 1px solid white;'>Password</td> <td><input type='password' name='password'></td> </tr>
<tr> <td style='border: 1px solid white;'>Connect</td> <td><input type='submit' value='Ok'></td> </tr>
</table>
</form>";
}
echo "</td></tr></table></center>";
?>
</body>
</html>
With this file, you can connect to your database, select which one you want to export, insert the name of the file and proceed. After this, it will let you download the exported Mysql file and after you downloaded it, it will let you delete it from server.
If you have permission problems, just create a folder say "myDB" and CHMOD it (means you give rights to that folder). Export to it like this: "myDB/myfile.sql".