On 23 Oct 2011, at 06:52, AmirBehzad Eslami wrote:

> Dear list,
> As you already know, there are different ways to retrieve a record-set
> from a database. For example, here's the classic way to perform this in PHP:
> 
> while ($row = mysql_fetch_assoc($db)) {
>   // my row is available here
> }
> 
> Speacking about PHP internals, what exactly happens here?
> 1) The PHP asks the Database-Layer to give a record in each while pass?
> I mean the record-set is not available in PHP's memory, but in MySQL's Mem.
> 
> 2) Or the database-layer has gave the whole result-set to PHP, and we're
> just fetching a single row from PHP's memory?

It depends what function was used to do the query...

mysql_query will fetch all result rows from MySQL into a buffer.

mysql_unbuffered_query does not.

Read the documentation for mysql_unbuffered_query carefully before you start 
using it: http://php.net/mysql_unbuffered_query

> 3) Finally, what is the efficient way to retrieve thousands or records which
> need to be processed at once? Using LIMIT?


Yes, use mysql_buffered_query, or mysql_query with limit to work through the 
results in a paginated fashion.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to