Changeset 47


Ignore:
Timestamp:
Oct 15, 2006, 5:25:05 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Use a config file for the DB parameters

Location:
trunk/npemap.org.uk/cgi
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/get-postcodes.fcgi

    r45 r47  
    88use JSON;
    99
     10use vars qw($dbname $dbhost $dbuser $dbpass);
     11
    1012sub print_err;
    1113sub setup_dbh;
     14
     15# Read in database config
     16my $config = 'npemap.conf';
     17do $config or die "Can't read $config!\n";
     18
    1219
    1320# Set up database handler to try and make sure it's ready for the first
     
    9299sub setup_dbh {
    93100    # $dbh is global
    94     return $dbh = DBI->connect_cached("dbi:Pg:dbname=npemaps;host=127.0.0.1","npemaps","npemaps");
     101    my $data_source = "dbi:Pg:dbname=$dbname";
     102    $data_source .= ";host=$dbhost" if $dbhost;
     103    return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    95104}
  • trunk/npemap.org.uk/cgi/submit.fcgi

    r44 r47  
    99use Date::Format;
    1010
     11use vars qw($dbname $dbhost $dbuser $dbpass);
     12
    1113sub print_err;
    1214sub setup_dbh;
     15
     16# Read in database config
     17my $config = 'npemap.conf';
     18do $config or die "Can't read $config!\n";
    1319
    1420# Set up database handler to try and make sure it's ready for the first
     
    152158sub setup_dbh {
    153159    # $dbh is global
    154     return $dbh = DBI->connect_cached("dbi:Pg:dbname=npemaps;host=127.0.0.1","npemaps","npemaps");
     160    my $data_source = "dbi:Pg:dbname=$dbname";
     161    $data_source .= ";host=$dbhost" if $dbhost;
     162    return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    155163}
     164
Note: See TracChangeset for help on using the changeset viewer.