mysql_num_rows vs mysql native count()
Friday, May 18th, 2007 in MySQLThe big question regarding this issue is: what is fater?
Let’s assume you need to build a pagination script. In order to find the total number of rows that will help you determine the number of total pages, you have to use either mysql_num_rows() or simply make your request using mysql’s count(). From my experience, when dealing with small result sets, it doesn’t make a huge difference what you use. But as always, a website expands. The database begins to grow, larger set results appear. And that’s exactly the moment when you’ll see the difference. That’s when simply using a query like “SELECT COUNT(*) AS total_number_of_rows FROM my_table” will save you sometimes even more than a second in your script execution.
I know this might not seem like much of an information or trick or hack or whatever, but I’ve worked on other people’s code and I’we seen it, or better said, not seen it in many ocasions.
Keep safe and fast till next time.






Leave a comment