Ignore:
Timestamp:
Oct 29, 2006, 6:10:20 PM (14 years ago)
Author:
Dominic Hargreaves
Message:

Better stats stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/scripts/content/update_stats.pl

    r220 r230  
    1313use lib "$FindBin::Bin/../../perllib";
    1414use NPEMap::Postcodes;
    15 
    16 use vars qw($dbname $dbhost $dbuser $dbpass);
     15use NPEMap;
    1716
    1817sub print_err;
    1918sub setup_dbh;
    2019
    21 # Read in database config
    22 my $config = 'npemap.conf';
    23 do $config or die "Can't read $config!\n";
    24 
    25 
    26 # No point in handling errors here since they'll get handled by the request
    27 # handler
    2820my $dbh;
    2921
    30 
    3122    # In case the database went away, make sure we have a connection
    32     unless (setup_dbh()) {
     23    unless ($dbh = setup_dbh()) {
    3324        print_internal_err('Error setting up database connection');
    3425    }
     
    3627build_home_stats($dbh);
    3728
    38 
    39 # No more requests to serve, so tidy up
    4029$dbh->disconnect;
    4130
     
    5241    print "Error: $err\n";
    5342}
    54 
    55 sub setup_dbh {
    56     # $dbh is global
    57     my $data_source = "dbi:Pg:dbname=$dbname";
    58     $data_source .= ";host=$dbhost" if $dbhost;
    59     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    60 }
Note: See TracChangeset for help on using the changeset viewer.