<?php
// 连接数据库
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 查询多表的总数
$sql = "SELECT COUNT(*) AS total_count FROM table1
JOIN table2 ON table1.id = table2.id
JOIN table3 ON table1.id = table3.id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出总数
while($row = $result->fetch_assoc()) {
echo "总数: " . $row["total_count"];
}
} else {
echo "没有结果";
}
// 关闭数据库连接
$conn->close();
?>
原文出处:http://www.dongblog.com/notes/47.html
来源:博客网 转载请注明出处!