Drupal 7 – Get number of returned rows on db_query()

db_query() returns a DatabaseStatementInterface object which has a function for retrieving the number of returned rows in the last SQL statement.

You could use the following piece of code to get the total number of nodes in Drupal.

$num_of_nodes = db_query('SELECT nid FROM {node}')->rowCount(); 

 

Done =)

Reference:

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.