285980 Quick PHP Script Edit
N/A
Thanh toán khi bàn giao
Hi,
I have php script that I need tweaked. Essentially, the script displays the the total of the row count for a table in several different databases. This is fine if all of the databases are on the same server, but I may using a load balancing solution where there are different users and hosts for each of the databases.
Could someone please tweak the script below:
[code]
<?
function count_rows($host, $username, $password, $databases, $tables) {
if(count($databases) != count($tables))
die("Must have same number of database and tables in array");
$totalCount = 0;
$conn = mysql_connect($host, $username, $password) or die("Unable to connect to database on $host as $username");
for($i = 0; $i < count($databases); $i++) {
mysql_select_db($databases[$i], $conn) or die("Unable to select $database[$i]");
$result = mysql_query("SELECT COUNT(*) as row_count FROM `$tables[$i]`") or die("Unable to select from $tables[$i]");
$row = mysql_fetch_assoc($result);
$totalCount += $row['row_count'];
}
return number_format($totalCount);
}
echo count_rows("localhost", "username", "password", array("database1", "database2"), array("table1", "table2"));
?>[/code]
ID dự án: #2032277