"Good Man" <heyho@letsgo.com> wrote in message
news:Xns964E69821BA84sonicyouth@216.196.97.131...[color=blue]
> Alvaro G Vicario <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
> news:wiwvzufqs5u0$.8uti3qqkho5d$.dlg@40tude.net:
>
>[color=green][color=darkred]
> >> after "//do stuff here" is done (and let's say its a LOT of stuff),
> >> and the next row of data is fetched, is the row of data coming from
> >> the database, or is it coming from the php variable $result?[/color]
> >
> > As far as I know, neither. PHP stores internally all the output from
> > the database query and $result is a pointer to that data. Function
> > mysql_fetch_array() fills an array with one row of this data.
> > Actually, it creates two elements per field, because it returns an
> > associative array and a regular array, check it with print_r().[/color]
>
> Actually, I believe you are wrong. It seems the first reply to this
> post, by Chris Hope, is correct:
>
> "Each call to mysql_fetch_array() will transfer a record from mysql to
> php. All that $result contains is a resource identifier to the
> resultset in mysql."
>
> ...so php *does* actually connect to the DB with each mysql_fetch_array
> ().
>
>[/color]
Actually, I don't agree... that would mean that internally, PHP is
submitting the query to MySQL every time you call 'mysql_fetch_array()'. To
make the point, when you submit the query you should see a certain amount of
disk activity/time lag (depending on your db size - especially since you are
requesting everything), but the code where you actually request the
results - 'mysql_fetch_array()' should run very quickly. To prove this,
simply echo some 'date/time' info before and after the query and at the
start of each loop through the result set.
Your time lag may be very small as you are only accessing 4000 rows, try a
test table of 100,000 rows...
Norm
--
FREE Avatar hosting at
www.easyavatar.com
[color=blue]
>[color=green][color=darkred]
> >> .. and THEN do my things by iterating through an array
> >>
> >> foreach ($Email as $key=>$value) {
> >> /* do stuff here (send $Name[$key] a letter to her email address
> >> of
> >> $value) */
> >> }[/color]
> >
> > I'd say this is a waste of memory. You create two arrays that contain
> > all the rows, while apparently you only need one row at a time.[/color]
>
> As above, it turns out that while it might *use* more memory, it is not a
> waste because my database connection is over and done with by this point,
> and I can do whatever I want to each row of data, regardless of execution
> time, and not worry about losing my database connection/the next row of
> data. I've modified my array generation to Chris Hope's suggestion:
>
> while ($row = mysql_fetch_array($result)) {
> $records[] = $row;
> }
>
>
>[color=green][color=darkred]
> >> Basically I'm attempting to avoid any chance of losing a mysql
> >> connection because the "//do stuff here" is taking so long....[/color]
> >
> > It's always a good idea to optimize queries:
> >
> > * Read only the fields you need (not all of them).
> > * Use LIMIT if applicable.
> > * If using WHERE clauses, create indexes for the searched fields.[/color]
>
> My question was really about database connections... there is nothing
> wrong with my query, I *need* all the field and rows that I've called...
> it's just that there is a significant amount of processing that must be
> done with each row of data, and I wanted to do that processing without
> losing my DB connection/next row of data.
>
> Chris Hope's suggestions worked wonderfully.
>
> Thanks for your help though! Cheers!
>
>
>
>
>
>
>[/color]