Addition within a loop
Posted: Fri Jul 16, 2010 9:25 am
Hi,
I have a script that checks the Master status from a set of MySQL databases. At prsent the script is quite long as I have coded a separate instance for each database, but I am thinking I should be able to put it into a function and loop it instead. However I can't find a way to increment it to the next database each time.
What I have so far is:
But somehow I need a way to increment $connection01 to $connection02, and $db1 to $db2. Is there an easy way to do this?
I have a script that checks the Master status from a set of MySQL databases. At prsent the script is quite long as I have coded a separate instance for each database, but I am thinking I should be able to put it into a function and loop it instead. However I can't find a way to increment it to the next database each time.
What I have so far is:
Code: Select all
function functionMasterQuery() {
$mysqlU="root";
$mysqlP="";
$connection01 = mysql_connect("localhost:3306", $mysqlU, $mysqlP);
$connection02 = mysql_connect("localhost:3307", $mysqlU, $mysqlP);
$connection03 = mysql_connect("localhost:3308", $mysqlU, $mysqlP);
$connection04 = mysql_connect("localhost:3309", $mysqlU, $mysqlP);
$connection05 = mysql_connect("localhost:3310", $mysqlU, $mysqlP);
$masterquery = "Show processlist";
$db1 = "MySQL01";
$db2 = "MySQL02";
$db3 = "MySQL03";
$db4 = "MySQL04";
$db5 = "MySQL05";
While($a<6) {
connection = $connection01;
$db = $db1;
$result = mysql_query ($masterquery, $connection);
while ($row = mysql_fetch_assoc($result)) {
if($row['Command'] == "Binlog Dump"){
echo "<tr><td>$db</td>";
echo "<td>",$row["Host"],"</td>";
echo "<td>",$row["State"],"</td></tr>";
} else {
echo "";
}
}
}
}
?>
<head></head>
<body>
<table><?php functionMasterQuery() ?></table>
</body>