What are the benefits of using SQL_CALC_FOUND_ROWS in conjunction with SELECT FOUND_ROWS() for determining the total number of records in a database query in PHP?

When using SQL_CALC_FOUND_ROWS in conjunction with SELECT FOUND_ROWS(), you can efficiently determine the total number of records in a database query without having to run a separate count query. This can improve performance by reducing the number of database queries needed to fetch the total count of records.

// Execute the main query with SQL_CALC_FOUND_ROWS
$result = $pdo->query("SELECT SQL_CALC_FOUND_ROWS * FROM your_table WHERE your_condition");

// Fetch the results of the main query
$rows = $result->fetchAll(PDO::FETCH_ASSOC);

// Get the total count of records without running a separate count query
$totalCount = $pdo->query("SELECT FOUND_ROWS()")->fetchColumn();