|
Posted by peter on 05/08/07 00:21
> Hi there,
>
> I have written a script to update some tables. There are 15000 rows in my
> table and the table has about 35 fields.
>
> My PHP script first of all completes a select on the main table like so:
>
> select * from maintable
>
> Then I enter a for each statements which for each row in the main table,
> updates another table with a value from maintable. E.g.(psudoe-ish code)
>
> *************START*******
> requireonce Db.php
>
> DB connect(to db)
>
> select name, email, id from maintable
>
> For each (Row in maintable)
> Call subroutine which - DB connects to same database again (As in
> subroutine)
> subroutine performs an update to another (new) table
> all done and free to move onto next maintable row.
> End for each
>
> ********END**************
When you use foreach unless it is a reference to the original array it work
on a copy of the array. Also do you actually use all 35 fields if not then
you should change your query so that it only retrieves what you need to use
(not doing so wastes memory).
You may consider using a where clause if you do not actually need to work
with all 15000 rows.
Not knowing what db package you are using (but presuming mysql as the
engine) but it is possible to do a mysql query without loading all of the
results into memory by using the mysql_unbuffered_query() function.
Navigation:
[Reply to this message]
|