You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Vladimir S. Tikhonjuk" <vs...@vst.donetsk.ua> on 2006/08/20 12:18:24 UTC

Project config options

Hi all!

Here is my little example of how I keep my DBI connection options for
the project.
May be someone have better example for such task ?

1. /usr/local/lib/site_perl/Promtelecom/Config.pm:

============ BEGIN Config.pm ==========

package Promtelecom::Config;

use strict;

%Promtelecom::Config::DBIConnectionOption = (
  database => 'database',
  host => 'host',
  user => 'user',
  password => '123456',
  PrintError => 1,
  RaiseError => 1,
  AutoCommit => 0
);

1;

============ END Config.pm ==========

2. /etc/apache2/modules.d/apache-dbi-startup.pl:

============ BEGIN apache-dbi-startup.pl ==========
$ENV{MOD_PERL} or die "GATEWAY_INTERFACE not Perl!";
use Apache::DBI;
use Promtelecom::Config;
use strict;

$Apache::DBI::DEBUG = 1;

Apache::DBI->connect_on_init(
 
'dbi:Pg(PrintError=>'.$Promtelecom::Config::DBIConnectionOption{PrintError}.',RaiseError=>'.$Promtelecom::Config::DBIConnectionOption{RaiseError}.',AutoCommit
=>'.$Promtelecom::Config::DBIConnectionOption{AutoCommit}.'):dbname=web_promtelecom;host=localhost',
  $Promtelecom::Config::DBIConnectionOption{user},
  $Promtelecom::Config::DBIConnectionOption{password}
);

1;
============ END apache-dbi-startup.pl ==========

3. /etc/apache2/httpd.conf:

============ BEGIN PART httpd.conf ==========
PerlRequire "/etc/apache2/modules.d/apache-dbi-startup.pl"
============ END PART httpd.conf ==========

So, when I have to get database connection into some handle, I use
%Promtelecom::Config::DBIConnectionOption hash for connection options.


Best regards,
Vladimir S. Tikhonjuk