So I have a cgi script,
#!/usr/bin/perl -T
use strict;
use warnings;
use DBI;
use WebEngine;
my $dbh = DBI->connect('DBI:mysql:database', $username, $password)
|| die "Could not connect to database: $DBI::errstr";
my $we = WebEngine->new($dbh)
or die("Failed to instantiate WebEngine object:\n$!\n");
$userID = $we->register("MyUsername", $dbh);
This script creates a database handler and then uses a module I made to deal with most of the back-end of the site to register a username and return a userID number.
I have three questions about this.
Does creating this $dbh in this script increase performance by keeping a database connection open?
Could I put the $dbh in my module and not fear being inefficient?
Is there a security benefit to keeping the $dbh (and the associated info(I keep my pass in plain text in the code; is that bad?)) in the module that is not directly interacted with through my website?