Subversion Repositories VORC

Rev

Rev 155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 206
Line 8... Line 8...
8
#  $ENV{HOME} = "/tmp" unless $ENV{HOME};
8
#  $ENV{HOME} = "/tmp" unless $ENV{HOME};
Line 9... Line 9...
9
  
9
  
10
  # Connect to MySQL server, using hardwired name and password
10
  # Connect to MySQL server, using hardwired name and password
11
  sub connect {
11
  sub connect {
-
 
12
		my $DB = shift // "vorc";
Line 12... Line 13...
12
		my $DB = shift // "vorc";
13
		my $dbuser = shift // "";
13
		
14
		
Line 14... Line 15...
14
	  my $db_name = "rollerco_".$DB;
15
	  my $db_name = "rollerco_".$DB;
Line 15... Line 16...
15
  	my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
16
  	my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
16
		
17
		
17
    return connect_with_option_file($dsn) unless !(-f $ENV{HOME}.'/.my.cnf');
18
    return connect_with_option_file($dsn, $dbuser) unless !(-f $ENV{HOME}.'/.my.cnf');
Line 18... Line 19...
18
    
19
    
19
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
20
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
20
 	  return (DBI->connect ($dsn, "root", "*********", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
21
 	  return (DBI->connect ($dsn, "root", "*********", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
21
  }
22
  }
22
  
23
  
-
 
24
  # Connect to MySQL server, using name and password from the current
Line 23... Line 25...
23
  # Connect to MySQL server, using name and password from the current
25
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
Line -... Line 26...
-
 
26
  # when added to the DSN, specifies which option file to read.
-
 
27
  sub connect_with_option_file  {
-
 
28
  	my $dsn = shift;
-
 
29
  	my $dbuser = shift // "";
-
 
30
  	
-
 
31
	  $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
-
 
32
	  
-
 
33
	  if ($dbuser eq "OG") {
-
 
34
	  	my $connection = DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError => 0});
-
 
35
	  	return $connection unless !$connection;	    
24
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
36
	  } elsif ($dbuser =~ /^[12345]$/) {
25
  # when added to the DSN, specifies which option file to read.
37
	  	my $connection = DBI->connect ($dsn.".$_", undef, undef, {PrintError => 0, RaiseError => 0});
26
  sub connect_with_option_file  {
38
	  	return $connection unless !$connection;	    
27
  	my $dsn = shift;
39
	  } else {
28
  	
40
	    db_error ("Invalid User ID provided to WebDB::connect ($dbuser)");