-2

I don't know how to better describe it... Let's say I do this:

    $s = "SELECT * FROM myTable";
    $result = $conn->query($s);
    while ($r = $result->fetch_array(MYSQLI_ASSOC)) {
      // do something with $r[]...
    }

Now, suppose I want to re-scan the result WITHOUT running the query again.
How can I do a "fseek" at the beginning of the $result, so that I can re-read the data in memory?
I understand I could store the data as soon as I read it, but I guess why duplicating it, since it's probably still in memory somewhere?

Dharman
  • 26,923
  • 21
  • 73
  • 125
ZioBit
  • 825
  • 8
  • 27
  • Why not save the rows in an array or use methods like `fetch_all()`? – Progman May 28 '22 at 10:24
  • I said I do not want to save them because they are already in memory, so why wasting RAM? There has to be a pointer somewhere that can be re-set to the beginning... Sorry, I come from a time when my stacks in my real-time systems were 512bytes each, and had to survive interrupts happening inside their corresponding tasks ;) – ZioBit May 28 '22 at 10:26
  • Do you want to use `data_seek()`? Which API are you using? – Progman May 28 '22 at 10:28
  • I guess that's it! mysqli_data_seek($result, 0); should do the trick, thanks. If you post the answer I will approve it – ZioBit May 28 '22 at 10:32
  • you can call $result->close() so it won't be "in memory somewhere" anymore and thus having your data in array instead of memory somewhere you can get a perfect separation of concerns – Your Common Sense May 28 '22 at 10:50

0 Answers0