I’ve started to use mysql_data_seek () as an easy way to roll pagination transparently into my database class by shifting the pointer and reading the current ‘page’.
What are the performance implications of doing this? I am only reading the data I need into PHP itself, but in most cases the SELECT covers the whole table – is this bad, and will I hit problems with massive tables?
If I understand your idea you select all records in the table, then skip the first n*page records with mysql_data_seek() in order to “get to” the current page and read n records. If you have a lot of records you might not want to do that because http://php.net/mysql_data_seek says:
The difference between mysql_query() and the unbuffered version is that mysql_query() returns only after the whole result set has been copied from the MySQL server to the PHP process’ memory while after the unbuffered version each mysql_fetch_xyz() has to receive the next record from the server. If you have a lot of records and you have to transfer all of them for each single request that sounds a bit suboptimal.
I guess you want to do this to get the total amount of records and the current subset with only one query. With MySQL you can have both, a LIMIT clause and the total number of records (that would be in the result set without the LIMIT clause),
see http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows