MySQL Forums
Forum List  »  PHP

MYSQL mysqli_num_rows vs Select count()
Posted by: Mohammed Mohammed Rasly
Date: May 02, 2024 04:49AM

I am currently working on optimizing our database queries and came across two options that perform the same task get row count. but might have varying levels of efficiency. I was hoping you could shed some light on which one would be faster and more effective in terms of performance.

Option 1:
$query = "SELECT * FROM tb";
$q = mysqli_query($conn, $query);
$row = mysqli_num_rows($q);

Option 2:
$query = "SELECT count(id) as num FROM tb";
$q = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($q);

Options: ReplyQuote


Subject
Written By
Posted
MYSQL mysqli_num_rows vs Select count()
May 02, 2024 04:49AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.