Hello i'm intrigued by what happens behind the scenes when I do a DB query to a database from php.
I would like to know what is the exact life cycle of a mysql_query()
I ask this question because i need to know what is the best solution to count the number of rows from a query.
My query is performed to fetch records from a mysqlDb that will be displayed as a list of let's say 10 rows. If i hadn't put a sql
the query would have returned more rows.
So my second question is:
"How can i know "what would have been the total amount of rows from a query if i hadn't specified the LIMIT clause?" Although i need to specify the LIMIT because i don't want to pass to php 1000000000 hundred k records if i'm only going to use 10.
1. I thought that i should use mysql_affected_rows(), but this will return 10 (determined by the LIMIT clause)
2. I thought of doing 2 queries one without the LIMIT and then call mysql_affected_rows() and the second query with the LIMIT and then call mysql_fetch_array().
(that is why i wanted to know how mysql_query() function works. I wanted to know if there was a lot of overhead even if I didn't call mysql_fetch_array() for the first query)
3. I thought of querying once without LIMIT and then loop with mysql_fetch_array() and only save the records in php that i want.
(this is ok if i want record from 0 to 9 or even 100 to 109 but what if i want the last records: 10 000 to 10 009 ?)
Well now that you know what my life is all about, I hope you can figure a good solution.
Thank you for reading this far
Regards,
bilibytes