我的代码如下:
$sql="SHOW DATABASES WHERE `Database` NOT LIKE '%backup%' AND `Database` NOT LIKE 'mysql' AND `Database` NOT LIKE '%schema%'";
$query=mysql_query($sql,$connect);
while ($row = mysql_fetch_assoc($query)) {
$sql1="SHOW TABLES FROM `".$row['Database']."`";
$query1=mysql_query($sql1, $connect);
while( $row2 = mysql_fetch_assoc($query1) ) {
$row2=implode(" ",$row2);
$sql1="SELECT COUNT(*) FROM `".$row['Database']."`.`".$row2."`";
$query1=mysql_query($sql1,$connect);
echo implode(" ",mysql_fetch_assoc($query1)).'<br>';
}
}
我有两个数据库和两个表,有两个记录 上面的代码统计了每个数据库中每个表的每个记录,它将获取两个数据,这些数据包含每个表的记录号。
所以它会输出:
2
2
我需要的是总结它们,结果将是4.Help please?
答案 0 :(得分:1)
只需计算PHP中的总和:
$sql="SHOW DATABASES WHERE `Database` NOT LIKE '%backup%' AND `Database` NOT LIKE 'mysql' AND `Database` NOT LIKE '%schema%'";
$query=mysql_query($sql,$connect);
$total = 0;
while ($row = mysql_fetch_assoc($query)) {
$sql1="SHOW TABLES FROM `".$row['Database']."`";
$query1=mysql_query($sql1, $connect);
while($row2 = mysql_fetch_assoc($query1) ) {
$row2=reset($row2);
$sql2="SELECT COUNT(*) FROM `".$row['Database']."`.`".$row2."`";
$query2=mysql_query($sql2,$connect);
$total += mysql_result($query2, 0);
}
}
echo $total;
并且还停止使用 mysql _ * 函数,它们已被弃用...