首先执行两个PDO查询并将结果存储在$pdo_result_1和$pdo_result_2变量中。然后可以使用rowCount()方法获取每个结果集的行数,并将它们存储在变量中以便进一步比较。
示例代码:
$stmt1 = $pdo->query("SELECT * FROM table1"); $pdo_result_1 = $stmt1->fetchAll();
$stmt2 = $pdo->prepare("SELECT * FROM table2 WHERE field = ?"); $stmt2->execute([$value]); $pdo_result_2 = $stmt2->fetchAll();
$row_count_1 = count($pdo_result_1); $row_count_2 = count($pdo_result_2);
if ($row_count_1 > $row_count_2) { echo "Result 1 has more rows"; } elseif ($row_count_1 < $row_count_2) { echo "Result 2 has more rows"; } else { echo "Both results have the same number of rows"; }
注意:以上示例代码仅仅是展示了如何比较结果集的行数,如果需要比较具体的数据,需要根据查询结果去做进一步处理。