Please wait while we load your page...
 

Announcements

MySQLTool

More Tools. . .

We provide this tool for FREE! However, we would greatly appreciate your support so we can continue to develop more tools (online tools and downloadable tools). You can show your support by sharing / liking this tool on Facebook. You can also tweet this page to your Twitter followers and following us on Twitter.


mySQLTool is the perfect tool to manage your mySQL database:

Password Sentry mySQLTool features Repair/Optimize. Repair and/or optimize mySQL database tables: compile a list of tables in the database, and allow you to select which database(s) to repair and/or optimize. Repairing will repair corrupt tables - corrupt tables can result in the loss of data, mySQL errors, and even failure of mySQL server (which on some websites, that rely heavily on accessing mySQL, can result in site-wide issues). Optimizing will defragment fragmented databases tables - fragmented tables take up more disk space on web server hard drive, and reduce mySQL query performance and select query response time. This tool will ensure that your mySQL database is operating optimally.
Password Sentry mySQLTool features Search/Replace. Search selected mySQL database tables to find string, with option to replace with another string. Allows you do what normally could take up to hours to do when done manually via an app like phpMyAdmin.
Password Sentry mySQLTool features Query. Query one or more databases.
Password Sentry mySQLTool features Backup. Backup all your databases. Critical in case your mySQL server crashes, and you lose data. In such an eventuality, you can restore your database from backup.

mysqltool.php


<?php
##########################################################################
#  mySQLTool Version 2.00201510101
#
#  Created:		Oct 10, 2015
#  Updated:		Oct 10, 2015
#  Copyright:	2015 Password Sentry. All Rights Reserved
#
#  URL:			https://www.password-sentry.com/mysqltool/
##########################################################################
##########################################################################
#  Copyright Notice
##########################################################################
#  Any redistribution of this script without the expressed written consent
#  of Password Sentry is strictly prohibited. Copying any of the code
#  contained within this script and claiming it as your own is also
#  prohibited. You may not remove any of these header notices. By using
#  this code you agree to indemnify Password Sentry from any liability
#  that might arise from its use.
##########################################################################
#  Installation
##########################################################################
#  1. Name file as mysqltool.php
#  2. Define $db_host, $db_usr, $db_pwd below.
#  3. Upload to web server (Either upload to password protected directory,
# or delete from web server after done)
#  4. Call script from web browser.
$db_host	= 'localhost';
$db_usr		= '';
$db_pwd		= '';
##########################################################################
#  Do NOT change or alter the code below!
##########################################################################
error_reporting(0);
if (function_exists('date_default_timezone_set')) {
	date_default_timezone_set('UTC');
}
session_start();
ini_set(mysql.connect_timeout, 10);
if (! $_POST['submit1'] and ! $_GET['submit1'] and ! $_POST['submit2'] and ! $_GET['submit2'] and ! $_POST['submit3'] and ! $_GET['submit3'] and ! $_POST['submit4'] and ! $_GET['submit4']) {
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>mySQLTool</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style type="text/css">
body {
	color:#FFFFFF;
}
a.link {
	color:#FFFFFF;
	font-family:Verdana, Helvetica, sans-serif;
	font-size:12px;
	font-style:normal;
	font-weight:bold;
	text-decoration:none;
}
a.link:hover {
	color:#FFFFFF;
	font-family:Verdana, Helvetica, sans-serif;
	font-size:12px;
	font-style:normal;
	font-weight:bold;
	text-decoration:underline;
}
a.link2 {
	color:#0EB493;
	font-family:Verdana, Helvetica, sans-serif;
	font-size:12px;
	font-style:normal;
	font-weight:bold;
	text-decoration:none;
}
a.link2:hover {
	color:#0EB493;
	font-family:Verdana, Helvetica, sans-serif;
	font-size:12px;
	font-style:normal;
	font-weight:bold;
	text-decoration:underline;
}
.main_box {
	background:rgba(14, 180, 147, 1);
	border:1px solid #FFFF00;
	border-radius:30px;
	box-shadow:#EAEAEA 15px 15px 15px;
	height:900px;
	margin-left:auto;
	margin-right:auto;
	width:78%;
	-webkit-border-radius:30px;
	-moz-border-radius:30px;
	-webkit-box-shadow:#EAEAEA 15px 15px 15px;
	-moz-box-shadow:#EAEAEA 15px 15px 15px;
}
.special {
	color:#337147;
	text-decoration:none;
	font-weight:bold;
}
.special:hover {
	color:#337147;
	text-decoration:underline;
	font-weight:bold;
}
.title_bar {
	font-size:20px;
	color:#FFF;
	font-weight:bold;
	margin:10px;
	padding:10px;
	text-align:center;
	background:#0EB493;
}
.errorbox {
	background-color:#FFEBE8;
	border:1px solid #DD3C10;
	color:#333333;
	padding:10px;
	font-size:13px;
	font-weight:bold;
	text-align:center;
	width:100%;
}
.successbox {
	background-color:#E1FAEA;
	border:1px solid #10DD43;
	color:#333333;
	padding:10px;
	font-size:13px;
	font-weight:bold;
	text-align:center;
}
.button {
	border-radius:10px;
	-moz-border-radius:10px;
	-webkit-border-radius:10px;
	background:#0EB493;
	font-size:14px;
	border:solid 2px #FFFFFF;
	border-radius:10px;
	color:#FFFFFF;
	display:inline-block;
	font:bold 14px Helvetica, Arial, sans-serif;
	margin-right:10px;
	padding:7px 7px;
	position:relative;
	text-decoration:none;
	transition:border-color .218s;
}
.button:hover {
	background:#0B9075;
	color:#FFFFFF;
	border-color:#FFFFFF;
	box-shadow:0 1px 2px rgba(0, 0, 0, 0.15);
}
.button:active {
	color:#FFFFFF;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
// <![CDATA[
function confirmPost(id) {
	var agree	= confirm("Are you sure you want to continue?");
	if (agree) {
		return true;
	}
	else { return false; }
}
function continueButton(c, id) {
	document.getElementById('cbutton' + id).innerHTML			= "<input type=\"hidden\" name=\"c\" value=\"" + c + "\"><input class=\"button\" type=\"submit\" name=\"submit" + id + "\" value=\"Continue\">";
}
function undocontinueButton(id) {
	document.getElementById('cbutton' + id).innerHTML			= "";
}
function showTab(div) {
	document.getElementById('tab1').style.display				= 'none';
	document.getElementById('tab2').style.display				= 'none';
	document.getElementById('tab3').style.display				= 'none';
	document.getElementById('tab4').style.display				= 'none';
	document.getElementById(div).style.display					= 'block';
}
function listbox_selectall(listID, isSelect) {
	var listbox	= document.getElementById(listID);
	for(var count = 0; count < listbox.options.length; count++) { listbox.options[count].selected = isSelect; }
}
// ]]>
</script>
</head>
<body>
<?php
}
$version	= '2.00201510101';
$result		= get_file('http://www.password-sentry.com/scripts/version/version.php?app=mt');
function get_file($source) {
	if (function_exists('curl_init')) {
		$ch			= @curl_init($source);
		@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
		@curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		@curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		$contents	= @curl_exec($ch);
	}
	else { $contents = @file_get_contents($source); }
	return $contents;
}
if ($result and ($version != $result)) { $alert = "Your App is Out-of-Date :: Please <a class='link2' href='https://www.password-sentry.com/mysqltool/' target='new'>Upgrade</a>"; }
else { unset($alert); }
$conn		= @mysql_connect($db_host, $db_usr, $db_pwd);
if (! $_POST['submit1'] and ! $_GET['submit1'] and ! $_POST['submit2'] and ! $_GET['submit2'] and ! $_POST['submit3'] and ! $_GET['submit3'] and ! $_POST['submit4'] and ! $_GET['submit4']) {
	$res		= @mysql_list_dbs($conn);
	unset($dbs);
	while ($row = @mysql_fetch_object($res)) { $dbs[] = $row->Database; }
	sort($dbs);
?>
<div class="main_box">
	<table style="width:90%;" align="center">
		<tr>
			<td class="title_bar">mySQLTool Version <?php echo $version; ?></td>
		</tr>
		<?php if ($alert) { ?>
		<tr>
			<td class="errorbox"><?php echo $alert; ?></td>
		</tr>
		<?php } ?>
		<tr>
			<td>
			<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" target="results" name="submission">
			<input class="button" type="submit" name="submit" value="Repair/Optimize" onclick="showTab('tab1'); return false;" />
			<input class="button" type="submit" name="submit" value="Search/Replace" onclick="showTab('tab2'); return false;" />
			<input class="button" type="submit" name="submit" value="Query" onclick="showTab('tab3'); return false;" />
			<input class="button" type="submit" name="submit" value="Backup" onclick="showTab('tab4'); return false;" />
			<table style="width:100%;">
				<tr>
					<td>
					<select name="dbs[]" id="list1" size="10" multiple="multiple">
						<?php
						foreach ($dbs as $key => $val) {
						if ($val) {
						echo "			<option value=\"" . $val . "\">" . $val . "</option>\n";
						}
						}
						?>
					</select><br/>
					<a class="special" href="#" onclick="listbox_selectall('list1', true);return false;">select all</a>   
					<a class="special" href="#" onclick="listbox_selectall('list1', false);return false;">unselect all</a>
					</td>
					<td>
					<textarea name="notice" cols="80" rows="10">It is HIGHLY recommended that you backup your database(s) before you run [Search/Replace] or [Query].
Product: mySQLTool
Author: Password Sentry
License: Copyright (c) <?php echo date('Y'); ?> Password Sentry
Any redistribution of this application without the expressed written consent of Password Sentry is strictly prohibited. Copying any of the code contained within this application and claiming it as your own is also prohibited. You may not remove any header notices from this application. By using this application, you agree to indemnify Pzassword Sentry from any liability that might arise from their use.
THIS APPLICATION IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</textarea>
					</td>
				</tr>
				<tr>
					<td colspan="2">
					<div id="tab1" style="width:100%;">
					<table style="height:200px;">
						<tr>
							<td><b>Repair:</b></td>
							<td><input type="checkbox" name="repair" value="1" checked="checked" /></td>
						</tr>
						<tr>
							<td><b>Optimize:</b></td>
							<td><input type="checkbox" name="optimize" value="1" checked="checked" /></td>
						</tr>
						<tr>
							<td><b>Auto Advance:</b></td>
							<td>
							<select name="auto1" size="1">
								<option value="0" selected="selected">No</option>
								<option value="1">Yes</option>
							</select>
							</td>
						</tr>
						<tr>
							<td colspan="2">
							<div id="sbutton1">
								<input class="button" type="submit" name="submit1" value="Submit" onclick="return confirmPost(1);" />
								<span id="cbutton1"></span>
							</div>
							</td>
						</tr>
					</table>
					</div>
					<div id="tab2" style="width:100%;display:none;">
					<table style="height:200px;">
						<tr>
							<td><b>Search For:</b></td>
							<td><input type="text" name="search" size="25" value="" /></td>
						</tr>
						<tr>
							<td><b>Replace With:</b></td>
							<td><input type="text" name="replace" size="25" value="" /></td>
						</tr>
						<tr>
							<td><b>Find:</b></td>
							<td>
							<select name="find" size="1">
								<option value="0" selected="selected">Partial Match</option>
								<option value="1">Exact Match</option>
							</select>
							</td>
						</tr>
						<tr>
							<td><b>Show:</b></td>
							<td>
							<select name="show" size="1">
								<option value="0" selected="selected">All Results</option>
								<option value="1">Only Matches</option>
							</select>
							</td>
						</tr>
						<tr>
							<td><b>Auto Advance:</b></td>
							<td>
							<select name="auto" size="1">
								<option value="0" selected="selected">No</option>
								<option value="1">Yes</option>
							</select>
							</td>
						</tr>
						<tr>
							<td colspan="2">
							<div id="sbutton2">
								<input class="button" type="submit" name="submit2" value="Search" onclick="return confirmPost(2);" />
								<span id="cbutton2"></span>
							</div>
							</td>
						</tr>
					</table>
					</div>
					<div id="tab3" style="width:100%;display:none;">
					<table style="height:200px;">
						<tr>
							<td><b>SQL Query:</b></td>
							<td><input type="text" name="query" size="25" value="" /></td>
						</tr>
						<tr>
							<td ><b>Auto Advance:</b></td>
							<td>
							<select name="auto" size="1">
								<option value="0" selected="selected">No</option>
								<option value="1">Yes</option>
							</select>
							</td>
						</tr>
						<tr>
							<td colspan="2">
							<div id="sbutton3">
								<input class="button" type="submit" name="submit3" value="Query" onclick="return confirmPost(3);" />
								<span id="cbutton3"></span>
							</div>
							</td>
						</tr>
					</table>
					</div>
					<div id="tab4" style="width:100%;display:none;">
					<table style="height:200px;">
						<tr>
							<td><b>Download Path:</b></td>
							<td><input type="text" name="path" size="25" value="backup" /></td>
						</tr>
						<tr>
							<td><b>Package As:</b></td>
							<td>
							<select name="package" size="1">
								<option value="0" selected="selected">Combined ZIP File</option>
								<option value="1">Individual Database ZIP Files</option>
							</select>
							</td>
						</tr>
						<tr>
							<td><b>Auto Advance:</b></td>
							<td>
							<select name="auto" size="1">
								<option value="0" selected="selected">No</option>
								<option value="1">Yes</option>
							</select>
							</td>
						</tr>
						<tr>
							<td colspan="2">
							<div id="sbutton4">
								<input class="button" type="submit" name="submit4" value="Backup" onclick="return confirmPost(4);" />
								<span id="cbutton4"></span>
							</div>
							</td>
						</tr>
					</table>
					</div>
					</td>
				</tr>
				<tr>
					<td colspan="2">
					<iframe style="background-color:#FFFFFF;width:100%;height:300px;" name="results"></iframe>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="text-align:center;"><b>© Copyright <?php echo date('Y'); ?> <a class="link" href="https://www.password-sentry.com/mysqltool/">Password Sentry</a>.
					All Rights Reserved.</b></td>
				</tr>
			</table>
			</form>			
			</td>
		</tr>
	</table>
</div>
</body>
</html>
<?php
}
else {
	function doerror($error, $id) {
		echo "<script type=\"text/javascript\">parent.undocontinueButton($id);</script>\n";
		echo "<div style='background-color:#FFEBE8;border:1px solid #DD3C10;color:#333333;padding:10px;font-size:13px;font-weight:bold;text-align:center;'>$error</div>";
		exit;
	}
	$c			= ($_POST['c']) ? $_POST['c'] : $_GET['c'];
	if (! $c) { $c = 0; }
	if ($_POST['submit1'] or $_GET['submit1']) {
		if (! $db_usr) { doerror("No [DB Username] defined in script!", 1); }
		if (! $db_pwd) { doerror("No [DB Password] defined in script!", 1); }
		if ($_POST['submit1'] == 'Submit') {
			$_SESSION['dbs']		= $_POST['dbs'];
			$_SESSION['repair']		= $_POST['repair'];
			$_SESSION['optimize']	= $_POST['optimize'];
			$_SESSION['auto1']		= $_POST['auto1'];
			$c						= 0;
			echo "<script type=\"text/javascript\">parent.undocontinueButton(1);</script>\n";
		}
		$dbs		= ($_POST['dbs'] ? $_POST['dbs'] : $_SESSION['dbs']);
		$repair		= ($_POST['repair'] ? $_POST['repair'] : $_SESSION['repair']);
		$optimize	= ($_POST['optimize'] ? $_POST['optimize'] : $_SESSION['optimize']);
		$auto		= (isset($_POST['auto1']) ? $_POST['auto1'] : $_SESSION['auto1']);
		unset($err);
		if (! $dbs) { $err .= "No [Databases] selected!<br/>\n"; }
		if (! $repair and ! $optimize) { $err .= "No action (Repair or Optimize) selected!<br/>\n"; }
		if ($err) { doerror($err, 1); }
		$i			= 0;
		if ($c >= count($dbs)) {
			echo "<script type=\"text/javascript\">parent.undocontinueButton(1);</script>\n";
			echo "<div style='background-color:#E1FAEA;border:1px solid #10DD43;color:#333333;padding:10px;font-size:20px;font-weight:bold;text-align:center;'>mySQL Job Done!</div>\n";
			unset($array, $dbs, $_GET, $_POST, $_SESSION);
			exit;
		}
		$db			= $dbs[$c];
		$res		= @mysql_query("SHOW TABLE STATUS FROM `" . $db . "`", $conn);
		if (! $res) { doerror('Cannot retrieve tables from mySQL: ' . mysql_error(), 1); }
		while ($data = @mysql_fetch_array($res)) {
			$array[$i]['database']	= $db;
			$array[$i]['table']		= $data['Name'];
			$array[$i]['Data_free']	= $data['Name'];
			$i++;
		}
		if (! $array or ! is_array($array)) { doerror('No tables found!', 1); }
		foreach ($array as $key => $val) {
			$db		= $val['database'];
			$res	= @mysql_select_db($db);
			if ($repair) {
				echo "<li>Repairing [$db." . $val['table'] . "] Table...";
				$res	= @mysql_query("REPAIR TABLE `" . $val['table'] ."`", $conn);
				if ($res) {
					echo " <span style='background-color:green;color:#FFFFFF;'>Done!</span></li>\n";
				}
				else {
					echo " <span style='background-color:red;color:#FFFFFF;'>Cannot Repair!</span></li>\n";
				}
			}
			else {
				echo "<li>Repair [$db." . $val['table'] . "] Table... <span style='background-color:#EAEAEA;color:#000000;'>Suppressed!</span></li>\n";
			}
			if ($optimize) {
				if ($val['Data_free'] > 0) {
					echo "<li>Optimizing [$db." . $val['table'] . "] Table...";
					$res	= @mysql_query("OPTIMIZE TABLE `" . $val['table'] ."`", $conn);
					if ($res) {
						echo " <span style='background-color:green;color:#FFFFFF;'>Done!</span></li>\n";
					}
					else {
						echo " <span style='background-color:red;color:#FFFFFF;'>Cannot Repair!</span></li>\n";
					}
				}
				else {
					echo "<li>Optimize [$db." . $val['table'] . "] Table... <span style='background-color:#EAEAEA;color:#000000;'>Not Required!</span></li>\n";
				}
			}
			else {
				echo "<li>Optimize [$db." . $val['table'] . "] Table... <span style='background-color:#EAEAEA;color:#000000;'>Suppressed!</span></li>\n";
			}
		}
		$c++;
		$u			= $_SERVER['PHP_SELF'] . "?c=$c&submit1=1";
		if ($auto) {
			echo "<meta http-equiv='refresh' content='2;url=$u'>\n";
		}
		else {
			echo "<script type=\"text/javascript\">parent.continueButton('$c', 1);</script>\n";
			echo "<a href='$u'>Continue</a>\n";
		}
	}
	elseif ($_POST['submit2'] or $_GET['submit2']) {
		if (! $db_usr) { doerror("No [DB Username] defined in script!", 2); }
		if (! $db_pwd) { doerror("No [DB Password] defined in script!", 2); }
		if ($_POST['submit2'] == 'Search') {
			$_SESSION['dbs']		= $_POST['dbs'];
			$_SESSION['replace']	= $_POST['replace'];
			$_SESSION['search']		= $_POST['search'];
			$_SESSION['find']		= $_POST['find'];
			$_SESSION['show']		= $_POST['show'];
			$_SESSION['auto']		= $_POST['auto'];
			$c						= 0;
			echo "<script type=\"text/javascript\">parent.undocontinueButton(2);</script>\n";
		}
		$dbs		= ($_POST['dbs'] ? $_POST['dbs'] : $_SESSION['dbs']);
		$search		= ($_POST['search'] ? $_POST['search'] : $_SESSION['search']);
		$replace	= ($_POST['replace'] ? $_POST['replace'] : $_SESSION['replace']);
		$find		= (isset($_POST['find']) ? $_POST['find'] : $_SESSION['find']);
		$show		= (isset($_POST['show']) ? $_POST['show'] : $_SESSION['show']);
		$auto		= (isset($_POST['auto']) ? $_POST['auto'] : $_SESSION['auto']);
		unset($err);
		if (! $dbs) { $err .= "No [Databases] selected!<br/>\n"; }
		if (! $search) { $err .= "No [Search For] phrase entered!<br/>\n"; }
		if ($err) { doerror($err, 2); }
		if ($c >= count($dbs)) {
			echo "<script type=\"text/javascript\">parent.undocontinueButton(2);</script>\n";
			echo "<div style='background-color:#E1FAEA;border:1px solid #10DD43;color:#333333;padding:10px;font-size:20px;font-weight:bold;text-align:center;'>mySQL Job Done!</div>\n";
			unset($array, $dbs, $_GET, $_POST, $_SESSION);
			exit;
		}
		$db			= $dbs[$c];
		echo "Searching Database [$db]....<br/>\n";
		$res	= @mysql_select_db($db);
		$res	= @mysql_query("SHOW TABLE STATUS FROM `" . $db . "`", $conn);
		if (! $res) { doerror('Cannot retrieve tables from mySQL: ' . mysql_error(), 2); }
		unset($tables);
		while ($data = @mysql_fetch_array($res)) {
			$tables[]	= $data['Name'];
		}
		if ($tables and is_array($tables)) {
			foreach ($tables as $key1 => $val1) {
				echo "      Searching Table [$val1]....<br/>\n";
				$res	= @mysql_query("SHOW COLUMNS FROM $val1");
				unset($fields);
				while ($rec = @mysql_fetch_array($res)) {
					if ($rec['Field']) { $fields[] = $rec['Field']; }
				}
				if ($fields and is_array($fields)) {
					foreach ($fields as $key2 => $val2) {
						if (! $find) {
							$res2	= @mysql_query("SELECT * FROM `$val1` WHERE `$val2` LIKE '%$search%'", $conn);
						}
						else {
							$res2	= @mysql_query("SELECT * FROM `$val1` WHERE `$val2` = '$search'", $conn);
						}
						if (@mysql_num_rows($res2) == 0) {
							if (! $show) { echo "              Searching Field [$val2]....<font color='red'>Not Found</font><br/>\n"; }
						}
						else {
							if ($replace) {
								$res3	= @mysql_query("UPDATE `$db` SET `$val1` = REPLACE(`$val1`, '$search', '$replace')", $conn);
								echo "              Searching Field [$val2]....<b><font color='green'>Found and Changed</font></b><br/>\n";
							}
							else {
								echo "              Searching Field [$val2]....<b><font color='green'>Found</font></b><br/>\n";
							}
						}
					}
				}
			}
		}
		$c++;
		$u			= $_SERVER['PHP_SELF'] . "?c=$c&submit2=1";
		if ($auto) {
			echo "<meta http-equiv='refresh' content='2;url=$u'>\n";
		}
		else {
			echo "<script type=\"text/javascript\">parent.continueButton('$c', 2);</script>\n";
			echo "<a href='$u'>Continue</a>\n";
		}
	}
	elseif ($_POST['submit3'] or $_GET['submit3']) {
		if (! $db_usr) { doerror("No [DB Username] defined in script!", 3); }
		if (! $db_pwd) { doerror("No [DB Password] defined in script!", 3); }
		if ($_POST['submit3'] == 'Query') {
			$_SESSION['dbs']		= $_POST['dbs'];
			$_SESSION['query']		= $_POST['query'];
			$_SESSION['auto']		= $_POST['auto'];
			$c						= 0;
			echo "<script type=\"text/javascript\">parent.undocontinueButton(3);</script>\n";
		}
		$dbs		= ($_POST['dbs'] ? $_POST['dbs'] : $_SESSION['dbs']);
		$query		= ($_POST['query'] ? $_POST['query'] : $_SESSION['query']);
		$auto		= (isset($_POST['auto']) ? $_POST['auto'] : $_SESSION['auto']);
		unset($err);
		if (! $dbs) { $err .= "No [Databases] selected!<br/>\n"; }
		if (! $query) { $err .= "No [SQL Query] entered!<br/>\n"; }
		if ($err) { doerror($err, 3); }
		if ($c >= count($dbs)) {
			echo "<script type=\"text/javascript\">parent.undocontinueButton(3);</script>\n";
			echo "<div style='background-color:#E1FAEA;border:1px solid #10DD43;color:#333333;padding:10px;font-size:20px;font-weight:bold;text-align:center;'>mySQL Job Done!</div>\n";
			unset($array, $dbs, $_GET, $_POST, $_SESSION);
			exit;
		}
		$db			= $dbs[$c];
		echo "Querying Database [$db]....";
		$res		= @mysql_select_db($db);
		if (! $res) { doerror('Cannot execute SQL Query: ' . mysql_error(), 3); }
		$res		= @mysql_query($query, $conn);
		if (! $res) { doerror('Cannot execute SQL Query: ' . mysql_error(), 3); }
		echo "Done!<br/>\n";
		$c++;
		$u			= $_SERVER['PHP_SELF'] . "?c=$c&submit3=1";
		if ($auto) {
			echo "<meta http-equiv='refresh' content='2;url=$u'>\n";
		}
		else {
			echo "<script type=\"text/javascript\">parent.continueButton('$c', 3);</script>\n";
			echo "<a href='$u'>Continue</a>\n";
		}
	}
	elseif ($_POST['submit4'] or $_GET['submit4']) {
		if (! $db_usr) { doerror("No [DB Username] defined in script!", 4); }
		if (! $db_pwd) { doerror("No [DB Password] defined in script!", 4); }
		if ($_POST['submit4'] == 'Backup') {
			$_SESSION['dbs']		= $_POST['dbs'];
			$_SESSION['path']		= $_POST['path'];
			$_SESSION['package']	= $_POST['package'];
			$_SESSION['auto']		= $_POST['auto'];
			$c						= 0;
			echo "<script type=\"text/javascript\">parent.undocontinueButton(4);</script>\n";
		}
		$dbs		= ($_POST['dbs'] ? $_POST['dbs'] : $_SESSION['dbs']);
		$path		= ($_POST['path'] ? $_POST['path'] : $_SESSION['path']);
		$package	= (isset($_POST['package']) ? $_POST['package'] : $_SESSION['package']);
		$auto		= (isset($_POST['auto']) ? $_POST['auto'] : $_SESSION['auto']);
		unset($err);
		if (! $dbs) { $err .= "No [Databases] selected!<br/>\n"; }
		if (! $path) { $err .= "No [Download Path] entered!<br/>\n"; }
		else {
			if (! file_exists($path)) { $err .= "Invalid [Download Path] entered - not found!<br/>\n"; }
			else {
				if (! is_writable($path)) { $err .= "[Download Path] not writable - try CHMODing the directory as 777 (rwxrwxrwx) via FTP!<br/>\n"; }
			}
		}
		if ($err) { doerror($err, 4); }
		if ($c >= count($dbs)) {
			echo "<script type=\"text/javascript\">parent.undocontinueButton(4);</script>\n";
			echo "<div style='background-color:#E1FAEA;border:1px solid #10DD43;color:#333333;padding:10px;font-size:20px;font-weight:bold;text-align:center;'>mySQL Job Done!</div>\n";
			unset($array, $dbs, $_GET, $_POST, $_SESSION);
			exit;
		}
		$db			= $dbs[$c];
		echo "Backing Up Database [$db]....";
		$date		= date("Y-m-d");
		$file		= "$path/$db.$date.sql";
		shell_exec("mysqldump --user=$db_usr --password=$db_pwd --databases $db > $file");
		if (! $package) {
			$zip		= `zip -j $path/$date.zip $file`;
		}
		else {
			$zip		= `zip -j $path/$db.zip $file`;
		}
		unlink($file);
		echo "Done!<br/>\n";
		$c++;
		$u			= $_SERVER['PHP_SELF'] . "?c=$c&submit4=1";
		if ($auto) {
			echo "<meta http-equiv='refresh' content='2;url=$u'>\n";
		}
		else {
			echo "<script type=\"text/javascript\">parent.continueButton('$c', 4);</script>\n";
			echo "<a href='$u'>Continue</a>\n";
		}
	}
	unset($array, $dbs, $_GET, $_POST);
}
?>


Live Chat Not Available