package SB::DB;

use strict;
use warnings;
use SB::Defaults qw($CONFIG);
use lib ('/usr/local/sitebuilder/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level');
use lib ('/usr/local/psa/lib/perl5/site_perl/5.8.8/mach');
use DBI;

BEGIN {
	use Exporter;
	our (@ISA, $VERSION, @EXPORT, @EXPORT_OK);
	$VERSION =  4.00;
	@ISA = qw(Exporter);
    @EXPORT    = qw();
    @EXPORT_OK = qw();
}

sub getSBHandle {
	my $dsn = "DBI:mysql:"
		. $CONFIG->{'database'}->{'dbname'} . ":"
		. $CONFIG->{'database'}->{'host'} . ":"
		. $CONFIG->{"internal"}->{'db_port'};
 	my $dbh = DBI->connect(
		$dsn,
 		$CONFIG->{"database"}->{'username'},
 		$CONFIG->{"database"}->{'password'},
 		{
 			PrintError => 0
 		}
 	);
	if (defined($DBI::errstr)) {
		$dbh = undef;
	}
	return $dbh;
}

sub getMysqlHandle {
	my $dsn = "DBI:mysql:mysql:"
		. $CONFIG->{'database'}->{'host'} . ":"
		. $CONFIG->{"internal"}->{'db_port'};

    my $dbh = DBI->connect(
		$dsn,
		$CONFIG->{"internal"}->{'db_admin_name'},
		$CONFIG->{"internal"}->{'db_admin_passwd'},
		{
			PrintError => 0,
			RaiseError => 0,
			AutoCommit => 1
		}
	);
	if (defined($DBI::errstr)) {
		$dbh = undef;
	}
	return $dbh;
}

1;

