1 package C4::Database; #asummes 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
38 my ($database,$hostname,$user,$pass,%configfile);
39 open (KC, "/etc/koha.conf");
43 if (/(.*)\s*=\s*(.*)/) {
46 # Clean up white space at beginning and end
51 $configfile{$variable}=$value;
54 $database=$configfile{'database'};
55 $hostname=$configfile{'hostname'};
56 $user=$configfile{'user'};
57 $pass=$configfile{'pass'};
59 my $dbh=DBI->connect("DBI:mysql:$database:$hostname",$user,$pass);
64 # Helper subroutine to make sure database handle was passed properly
68 $subrname, # name of calling subroutine
71 unless ( ref($dbh) =~ /DBI::db/ ) {
72 print "<pre>\nERROR: Subroutine $subrname called without proper DBI handle.\n" .
73 "Please contact system administrator.\n</pre>\n";
74 die "ERROR: Subroutine $subrname called without proper DBI handle.\n";