Subversion Repositories VORC

Rev

Rev 47 | Rev 63 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 1
package WebDB;
2
  use strict;
3
  use DBI;
4
  my $host_name = "192.168.1.5";
47 - 5
  my $db_name = "rollerco_vorc";
7 - 6
  my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
50 bgadell 7
  $ENV{HOME} = "/tmp" unless $ENV{HOME};
7 - 8
 
9
  # Connect to MySQL server, using hardwired name and password
10
  sub connect  {
50 bgadell 11
    return connect_with_option_file() unless !(-f $ENV{HOME}.'/.my.cnf');
12
 
13
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
7 - 14
 	  return (DBI->connect ($dsn, "root", "********",
15
	  {PrintError => 0, RaiseError => 1}));
16
  }
17
 
18
  # Connect to MySQL server, using name and password from the current
19
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
20
  # when added to the DSN, specifies which option file to read.
21
  sub connect_with_option_file  {
22
	  $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
23
	  return (DBI->connect ($dsn, undef, undef,
24
	  {PrintError => 0, RaiseError => 1}));
25
  }
26
 
50 bgadell 27
  # Quash any leading or trailing whitespace
7 - 28
  sub trim {
29
    my $str = shift;
30
 
31
  	return "" if !defined $str;
32
  	$str =~ s/^\s+//;
33
  	$str =~ s/\s+$//;
34
  	return ($str);
35
  }
50 bgadell 36
 
37
1; # return true