Murcia has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a problem with mysql and perl. I wrote a cgi that connects to a mysql database on linux. This cgi calls in a loop select-statements ... everything well

I tried to used it on Windows XP ... For a loop < 17 calls it works but bigger then 17 not ... It hangs up with no return to the browser ... When i break the cgi in the browser, it writes the result for <17 entries ...

WINDOWS XP APACHE SERVER MYSQL 4.0.13-nt ACTIVEPERL 5.8.0
I tried to use the linux mysql server with Windows (Apache Server, Perl) OK I tried to use the windows mysql server with Linux(Apache Server, Perl) OK in the mysql log in see just 17 Queries then it breaks
>> end ... 33 QUERY select .... 33 QUERY select ..... 030723 18:18:18 1 show status

Replies are listed 'Best First'.
Re: mysql perl hangs on selects
by talexb (Chancellor) on Jul 23, 2003 at 18:11 UTC

    Let me echo what the other two (so far) respondents have mentioned .. we gotta see some code or all we're doing is waving our hands (or arms).

    However, based on 'fails after more than 17', I'm guessing it might be that some buffer is getting full and there are problems allocating a second buffer. You've turned up the DBI->trace value, right? Does that tell you anything?

    --t. alex
    Life is short: get busy!
Re: mysql perl hangs on selects
by shemp (Deacon) on Jul 23, 2003 at 17:49 UTC
    When you say breaks, does your cgi die, and if so, what is the output of the apache error log?

    Potential reasons for breaking:
    • its not really dieing, but because a lot is getting written to error logs (for whatever reason), takes quite a while.
    • if you arent finish() ing your query handles within the loop, your program may be eating too many resources for mysql to handle, based on your configuration for max temp tables, etc. From Programming the Perl DBI (O'Reilly), Page 111: "After execute() returns successfully, the database has not necessarily completed the execution of the SELECT statement..."
    Anyway, the first thing i'd do is examine the mysql configs (show variables) for differences between the servers.
Re: mysql perl hangs on selects
by dbwiz (Curate) on Jul 23, 2003 at 18:04 UTC
Re: mysql perl hangs on selects
by Murcia (Monk) on Jul 24, 2003 at 07:27 UTC
    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; }

      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

      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);
      
      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?