[TYPO3-dev] Tip: use SQL function COUNT(*)

Martin Kutschker masi-no at spam-typo3.org
Fri Jul 18 13:00:00 CEST 2008


Martin Kutschker schrieb:
> Dmitry Dulepov [typo3] schrieb:
>> Hi!
>>
>> Ingo Renner wrote:
>>> Martin Kutschker wrote:
>>>> Anyway it's better to use this:
>>>>
>>>> $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(*)', 'tx_table');
>>> $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(uid)', 'tx_table');
>> My preferred:
>>
>> list($row) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('COUNT(*) AS t',
>> 'tx_table');
>> $count = $row['t'];
>>
>> No need top free resource. Less chances to forget freeing.
> 
> Very good.

Even better :)

$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('table');

Masi




More information about the TYPO3-dev mailing list