On Fri, 3 Jan 2003 03:51:05 +0200 Boris Penchev <[EMAIL PROTECTED]> wrote:
> Dear All,
>
> I has this fromlem when I have a lot of MySQL request. Now i do not have
> free time to explain this problem, but I give you smal
> example:
> my $sth = $dbh->prepare(qq~SELECT id, name FROM all~) || die
> "$DBI::errstr\n";
> $sth->execute();
# You are not checking for errors from the execute() above.
# Prepare() $sth2 here, not inside the loop.
# Declare $id and $name before starting the while loop.
> while ( my $id, $name = $sth->fetchrow_array() ) {
# You need parenthesis around ($id, $name) to provide a list
# context for $sth->fetchrow_array().
# bind_columns() and fetch() would be more effecient.
> my $sth2 = $dbh->prepare(qq~SELECT * FROM peopleaddress WHERE
> name = ?~) || die "$DBI::errstr\n";
> $sth2->execute($name);
> while (..............) {
> ....................
> }
> $sth2->finish();
> }
> $sth->finish();
>
> If you do not use finish() in these situation you might have big
> problems.
It would be helpful if you could say what the big problems are.
If it's a memory leak, try moving the prepare outside the loop.
You only need to prepare a statement once; you can then execute
it as many times as necessary without re-prepare()ing it.
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.