Jump to content

SQL - vs - PHP count


Suchy

Recommended Posts

Which method causes less stress on the MySQL server.

 

The SQL way:

$query = "SELECT COUNT(person_id) AS counter FROM video WHERE person_id = 1 AND public_account = 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$counter = $row['counter'];

 

or the PHP way:

$query = "SELECT person_id FROM video WHERE person_id = 1 AND public_account = 1";
$result = mysql_query($query);
$counter = mysql_num_rows($result);

 

All I need is to display amount of videos each person has.

Link to comment
https://forums.phpfreaks.com/topic/166382-sql-vs-php-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.