in reply to mysql perl hangs on selects

apache error_log shows no error!
perl.exe still runs ...

the select statement
SELECT table1.id, table1.id2, table1.id3 ,table2.name 
FROM table2, table1
WHERE table1.id = 'something' 
and 
table1.id=table2.id
my ($result_ref, $columnNames_ref, $numFields) = fetchRowArray($dbh, +$sql); ... sub fetchRowArray($$){ my $dbh = shift; my $sql = shift; my $sth = $dbh->prepare($sql) or meldeFehler("Statement could not pr +epared"); $sth->execute() or meldeFehler("Statement could not executed"); my $columnNames; $columnNames = $sth->{NAME}; my $numfields; $numfields = $sth->{NUM_OF_FIELDS}; my (@matrix) = (); while (my @ary = $sth->fetchrow_array()) { push(@matrix, [@ary]); } $sth->finish(); return \@matrix, $columnNames, $numfields; }

Replies are listed 'Best First'.
Re: Re: mysql perl hangs on selects
by dbwiz (Curate) on Jul 24, 2003 at 08:46 UTC

    I don't see any reason for your code to hang in this snippet. Maybe you can optimize it a bit, as in the example below, but there is nothing so wrong that it could cause a halt.

    sub fetchRowArray($$){ my $dbh = shift; my $sql = shift; my $sth = $dbh->prepare($sql) or die("statement can't be prepared"); $sth->execute() or die("Statement can't be executed"); my $columnNames = $sth->{NAME}; my $numfields= $sth->{NUM_OF_FIELDS}; my $matrix) = $sth->fetchall_arrayref(); return $matrix, $columnNames, $numfields; }

    What is not clear in your request is this: you say that your code stops after 17 loops and later that the MySQL log shows 17 queries. Therefore, maybe the reason for hanging is not in this loop, but some other place in your script.

    The candidates for further scrutiny are, then, your sub meldeFehler and the point from where your are calling fetchRowArray.

    Please clarify what you mean by loop. If you mean that it hangs after 17 successful queries, then you may have a memory problem. If you mean that it hangs when the records are more than 17, then I don't see the cause here.

    As a piece of practical advice, I would recommend to run this script from the command line, to see if the result is what you expected, and put some print statements in the critical points (printing, for example, "inside meldeFehler", "before calling fetchRowArray", and so on) so that you get a clear idea of where exactly the code stops.

    HTH

Re: Re: mysql perl hangs on selects
by nite_man (Deacon) on Jul 24, 2003 at 08:35 UTC
    You can use DBI method fetchall_arrayref()
    my $matrix = $sth->fetchall_arrayref();
    instead of
    my (@matrix) = (); while (my @ary = $sth->fetchrow_array()) { push(@matrix, [@ary]); } }

    Can you show a part of your script which generates an HTML page?

          
    --------------------------------
    SV* sv_bless(SV* sv, HV* stash);
    
Re: Re: mysql perl hangs on selects
by Murcia (Monk) on Jul 24, 2003 at 09:04 UTC
    Thanks first for hints ....
    The code works fine on Linux!!!!
    And the cgi (running under Windows with the Apache server) works well with the Linux mysql server.
    It must be the communication between perl and mysql in Windows , or?