1 package C4::Database; #assumes C4/Database
3 #requires DBI.pm to be installed
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
26 use vars qw($VERSION @ISA @EXPORT);
32 &C4Connect &requireDBI &configfile
37 open (KC, "/etc/koha.conf");
41 if (/(.*)\s*=\s*(.*)/) {
44 # Clean up white space at beginning and end
49 $configfile->{$variable}=$value;
57 my ($database,$hostname,$user,$pass,%configfile);
58 open (KC, "/etc/koha.conf");
62 if (/(.*)\s*=\s*(.*)/) {
65 # Clean up white space at beginning and end
70 $configfile{$variable}=$value;
73 $database=$configfile{'database'};
74 $hostname=$configfile{'hostname'};
75 $user=$configfile{'user'};
76 $pass=$configfile{'pass'};
78 my $dbh=DBI->connect("DBI:mysql:$database:$hostname",$user,$pass);
84 &requireDBI($dbh, $functionnname);
86 Verifies that C<$dbh> is a valid DBI::db database handle (presumably
87 to the Koha database). If it isn't, the function dies.
89 C<$functionname> is the name of the calling function, which will be
90 used in error messages.
95 # Helper subroutine to make sure database handle was passed properly
99 $subrname, # name of calling subroutine
100 # FIXME - Ought to get this with 'caller',
101 # instead of requiring developers to always
102 # get it right. Plus, it'd give the line
106 unless ( ref($dbh) =~ /DBI::db/ ) {
107 print "<pre>\nERROR: Subroutine $subrname called without proper DBI handle.\n" .
108 "Please contact system administrator.\n</pre>\n";
109 die "ERROR: Subroutine $subrname called without proper DBI handle.\n";