Database access · Question 10 of 12

For an overview, only the number of entries on page 12 should be counted. Which implementation is the most efficient?

1 answer is correct. Medium

Show answer

Answer

  • D $qb->count('uid')->from('tx_myext_item')->where($qb->expr()->eq('pid', $qb->createNamedParameter(12, Connection::PARAM_INT)))->executeQuery()->fetchOne()

Explanation

count() replaces the SELECT part with COUNT(), the database only returns a number, which fetchOne() reads. Loading all rows and counting them in PHP costs memory and time. rowCount() is not reliable for SELECT on all database systems, and select('COUNT(*)') would quote the expression as a column name.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications