in reply to Persistent database connections show incorrect results

It's hard to tell what the problem is without seeing any code, but I'm guessing it happens as soon as you hit any child process the second time. It probably has to do with something being persistent that you didn't expect. Check it by running in single-process mode: httpd -X. It's probably not related to Apache::DBI or persistent database connections.
  • Comment on Re: Persistent database connections show incorrect results

Replies are listed 'Best First'.
Re: Re: Persistent database connections show incorrect results
by PB (Initiate) on Apr 17, 2002 at 19:59 UTC
    Thanks for the respones.
    Yes I mean lexical .
    I tried running httpd -X, and then it happens immediately ie: the second time I submit the form it has the values from the first time.

    Here is the code.

    use strict vars; use CGI qw(param); use diagnostics ; # Constants my $db = "ecreditdb"; my $server = "localhost"; my $user = "updater"; my $password = "1q2w3e4r"; # CGI Parameters my $Id = param("ID"); my $Fname = param("Fname"); sub init { # Connect to database my $dbh = ''; $dbh = DBI->connect("DBI:mysql:$db:$server", $user,$password); if (! $dbh) { print "Could not connect to $db on $server\n"; } $dbh->{RaiseError} = 1; # Prepare and run the query my $query="INSERT INTO clients values( \"$Fname\",\"$Id\") ;"; my $sth = $dbh->prepare_cached("$query") or die "Can't prepare stateme +nt: $dbh->errstr \n"; $sth->execute or die "Can't execute statement", $dbh->errstr ; $sth->finish; $dbh->disconnect(); disp(); } # End sub disp { print " <html> <head> <title>Update completed successfully</title> </head> <body bgcolor=\"#CCCCCC\"> <p align=\"center\"><font face=\"Courier New\" size=\"4\"><b><br> <font color=\"#000000\">Update completed successfully</font></b></font +></p> <p align=\"center\">&nbsp;</p> <p align=\"center\"> <b><font color=\"#8000000\">Please logon again !! </font></b></p> <p align=\"center\">&nbsp;</p> <p align=\"center\"> <a href=\"/private/login.htm\">Press here to logon</a></p> </body> </html> "; } init();


    Thanks
      You have am unintentional closure, created by using subroutines that refer to lexicals declared outside their scope. This is a known problem with Apache::Registry (but not with standard mod_perl handlers written to the mod_perl API). You can fix it by moving the CGI parameter code inside the init sub.

      For more on this topic, see the guide. Also, turn on warnings use full strict (not just vars) to catch this sort of problem.

        Hi Perrin

        That solved it, it makes sense now.

        Thanks a million!
        Paul