Drupal 8 Looking for an elegant alternative of rowCount in a query
According to the Drupal API, "in D8 rowCount() is the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed or throws \Drupal\Core\Database\RowCountException if the last executed statement was SELECT."

If you need to select count of rows you can use $query->addExpression('COUNT(*)');

   $query = \Drupal::database()-&gt;select('table', 't');
   $query-&gt;addExpression('COUNT(*)');
   $count = $query-&gt;execute()-&gt;fetchField();