Re: memory limit exceeded
| From: | Hans H. Anderson | Date: | Tue, 18 Jul 2000 15:03:38 +0000 |
| Subject: | Re: memory limit exceeded | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7093@lists.php.net to get a copy of this message | ||
Gunjan,
You might have a reason that is not clear to me based on this post, but
why are you putting all that information into the $data array? That's
your memory hog right there. IMHO, you are making this script a lot more
complex than it needs to be. For one, you can bypass the whole
select_MYSQL function by just doing this:
$result = mysql_query("select * from Table");
while($result_set=mysql_fetch_array($result)) {
// stuff you where doing in your test.php
// for loop here
}
($result_set is an array of the current row, if you have columns
Name,Email,ID, you would get them this way: $result_set["Name"],
$result_set["Email"], $result_set["ID"], etc.)
Hans
On Tue, 18 Jul 2000, Gunjan Kapoor wrote:
>
> hi,
> I'm running the following scripts which retrieve about 20000+ records from
> the MySQL database. I'm using PHP4 on Apache (UNIX). However the script
> execution completes only once. The second time onwards it gives a "memory
> limit of 16 MB exceeded error".
> I am using mysql_free_result. so that should not be an issue.B
>
> <?php
> //tst_db.php
> function start_MYSQL ($host, $user, $passwd, $db)
> {
> if (!($conn = mysql_pconnect ($host, $user, $passwd)))
> { exit(); }
>
> if (!mysql_select_db ($db, $conn))
> { exit(); }
> return $conn;
> }
>
>
> function end_MYSQL ($conn)
> {
> if (!(mysql_close ($conn)))
> { exit(); }
> }
>
> function select_MYSQL ($conn, $stmt)
> {
> if (!($result = mysql_query ($stmt, $conn)))
> { exit(); }
>
> $rows = array();
> for ($i = 0; ($row = mysql_fetch_array($result)); $i++)
> {
> $rows[$i] = $row;
> }
>
> mysql_free_result ($result);
> return $rows;
> }
>
> ?>
>
>
>
>
>
>
>
> <?php
> // tst.php
> require ("tst_db.php");
> $conn = start_MYSQL ("", "gkapoor", "gkapoor",
> "eprowess");
>
> $COS = array();
> $query = "select entity from kompany";
> $rows = select_MYSQL ($conn, $query);
> for ($i = 0; $i < count($rows); $i++)
> {
> $co = $rows[$i]['entity'];
> array_push ($COS, $co);
> }
>
> $set = 100;
> for ($i = 0, $lim = count($COS); $lim > 0; $lim-=$set, $i+=$set)
> {
> $set = (($lim > $set) ? $set : $lim);
> $cos = join (", ", array_slice($COS, $i, $set));
>
> $query = "select kcompany, return from stocks where kcompany
> in ($co
> s) and date between \"$from\" and \"$to\"";
> $rows = select_MYSQL ($conn, $query);
>
> $old_co = ""; $tot_ret = 1;
> unset($rows); unset ($cos);
> }
> unset ($COS);
> ?>
>
> TIA
> Gunjan
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>
Hans Anderson ~ me@hansanderson.com
PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL
(800)397-9116 / (406)549-6524 | Databases, Flash Multimedia,
http://www.hansanderson.com | Killer Audio Production,
http://www.goofiness.com | Minty Fresh Breath.