tags:

views:

360

answers:

2

Hi,

Which is the equivalent of mysql_data_seek using pdo objects? Can you give me an example?

Thanks!

A: 

I found the answer to my question in this thread: http://stackoverflow.com/questions/278259/is-it-possible-to-rewind-a-pdo-result

Lucia
A: 

The usual answer is: do your data seek directly in the array PDOStatement::fetchAll... But it is WRONG IF the query fetches a lot of data (!).

There are 2 real solutions,

1) if database permits use PDO::FETCH_ORI_ABS or PDO::FETCH_ORI_REL, example,

$result = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 973);

2) use the database solution (a kind of pagination). Example:

SELECT a, b FROM table OFFSET 973 LIMIT 1 
Peter Krauss