use global $dbh variable correctly
authorTroy Sankey <sankeytms@gmail.com>
Sat, 8 Feb 2014 07:09:04 +0000 (23:09 -0800)
committerTroy Sankey <sankeytms@gmail.com>
Sat, 8 Feb 2014 07:09:04 +0000 (23:09 -0800)
index.pl

index 4cafb5c..5ec76b4 100755 (executable)
--- a/index.pl
+++ b/index.pl
@@ -167,11 +167,12 @@ sub connect_cache {
 # Description:
 ###############################################################################
 sub connect_db {
-  my $dbh = DBI->connect("DBI:Pg:database=$db_database;host=$db_hostname",
-                         "$db_username",
-                         "$db_password",
-                         {pg_enable_utf8 => 1});
-  return $dbh;
+  if (!defined $dbh) {
+    $dbh = DBI->connect("DBI:Pg:database=$db_database;host=$db_hostname",
+                        "$db_username",
+                        "$db_password",
+                        {pg_enable_utf8 => 1});
+  }
 }
 
 ###############################################################################
@@ -417,7 +418,7 @@ sub handle_submit {
     print $q->end_html;
     return;
   }
-  $dbh = connect_db();
+  connect_db();
   my ($party_idx,$party_datetime) = get_next_party();
   if (!defined $party_idx) {
     print "<p style=\"color:red\">Registration closed :-(</p>";
@@ -458,7 +459,7 @@ sub print_body_home {
   print $q->header(-type=>"text/html", -charset=>"utf-8");
   print $q->start_html(-title=>$page_title, -encoding=>"UTF-8");
   print_head();
-  $dbh = connect_db();
+  connect_db();
   if (not $dbh) {
     print_database_error();
     print_tail();
@@ -500,7 +501,7 @@ sub print_body_home {
 }
 
 sub print_body_keylists {
-  $dbh = connect_db();
+  connect_db();
   if (not $dbh) {
     print $q->header(-type=>"text/html", -charset=>"utf-8");
     print $q->start_html(-title=>$page_title, -encoding=>"UTF-8");