5 use vars
qw($AUTOLOAD @ISA);
9 MOBY::mysql - makes a MYSQL database connection.
13 use MOBY::simple_output;
14 my $dbh = MOBY::central_db_connection->new(
15 db_connect_object => "MOBY::mysql",
16 username => "myusername"
17 password => "mypassword",
22 $sth = $dbh->prepare("select * from tablename");
29 makes a mysql conneciton to the database. Should be created via
30 a central_db_connection object only!
34 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
43 #___________________________________________________________
45 my %_attr_data = # DEFAULT ACCESSIBILITY
48 #_____________________________________________________________
49 # METHODS, to operate on encapsulated class data
50 # Is a specified object attribute accessible in a given mode
52 my ( $self, $attr, $mode ) = @_;
53 $_attr_data{$attr}[1] =~ /$mode/;
56 # Classwide default value for a specified object attribute
58 my ( $self, $attr ) = @_;
59 $_attr_data{$attr}[0];
62 # List of names of all specified object attributes
69 my ( $caller, $dbname, $username, $password, $host, $port ) = @_;
71 my $caller_is_obj = ref($caller);
72 return $caller if $caller_is_obj;
73 my $class = $caller_is_obj || $caller;
75 my $self = bless {}, $class;
76 my ($dsn) = "DBI:mysql:$dbname:$host:$port";
78 && &_LOG("connecting to db with params $dbname, $username, $password\n");
79 my $dbh = DBI->connect( $dsn, $username, $password, { RaiseError => 1 } )
80 or die "can't connect to database";
81 $debug && &_LOG("CONNECTED!\n");
82 $self->databasehandle($dbh);
88 my ( $self, $newval ) = @_;
89 $AUTOLOAD =~ /.*::(\w+)/;
91 if ( $self->_accessible( $attr, 'write' ) ) {
93 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
94 return $_[0]->{$attr};
95 }; ### end of created subroutine
96 ### this is called first time only
97 if ( defined $newval ) {
98 $self->{$attr} = $newval;
100 return $self->{$attr};
101 } elsif ( $self->_accessible( $attr, 'read' ) ) {
103 return $_[0]->{$attr};
104 }; ### end of created subroutine
105 return $self->{$attr};
108 # Must have been a mistake then...
109 croak "No such method: $AUTOLOAD";