note 115856 added to sqlite3result.fetcharray
| From: | Jason | Date: | Fri, 03 Oct 2014 22:21:18 +0000 |
| Subject: | note 115856 added to sqlite3result.fetcharray | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200583@lists.php.net to get a copy of this message | ||
Would just like to point out for clarification that each call to fetchArray() returns the next
result from SQLite3Result in an array, until there are no more results, whereupon the next
fetchArray() call will return false.
HOWEVER an additional call of fetchArray() at this point will reset back to the beginning of the
result set and once again return the first result. This does not seem to explicitly documented, and
caused me my own fair share of headaches for a while until I figured it out.
For example:
<?php
$returned_set = $database->query("select query or whatever");
//Lets say the query returned 3 results
//Normally the following while loop would run 3 times then, as $result wouldn't be
false until the fourth call to fetchArray()
while($result = $returned_set->fetchArray()) {
//HOWEVER HAVING AN ADDITIONAL CALL IN THE LOOP WILL CAUSE THE LOOP TO RUN AGAIN
$returned_set->fetchArray();
}
?>
Basically, in the above code fetchArray will return:
1st call | 1st result from $returned_set (fetchArray() call from while condition)
2nd call | 2nd result (fetchArray() call from while block)
3rd call | 3rd result (fetchArray() call from while condition)
4th call |FALSE (fetchArray() call from while block)
5th call | 1st result (fetchArray() call from while condition)
....
This will cause (at least in this case) the while loop to run infinitely.
----
Server IP: 72.52.91.14
Probable Submitter: 24.253.38.51
----
Manual Page -- http://php.net/manual/en/sqlite3result.fetcharray.php
Edit -- https://master.php.net/note/edit/115856
Del: integrated -- https://master.php.net/note/delete/115856/integrated
Del: useless -- https://master.php.net/note/delete/115856/useless
Del: bad code -- https://master.php.net/note/delete/115856/bad+code
Del: spam -- https://master.php.net/note/delete/115856/spam
Del: non-english -- https://master.php.net/note/delete/115856/non-english
Del: in docs -- https://master.php.net/note/delete/115856/in+docs
Del: other reasons-- https://master.php.net/note/delete/115856
Reject -- https://master.php.net/note/reject/115856
Search -- https://master.php.net/manage/user-notes.php