Use of "my $dbh=C4Connect;"
We're developing a script to load data for the biblio, biblioitems, and items tables of the koha MySQL database using DBI and we're wondering what to use for our database handle. I can see that in a number of the koha scripts the command my $dbh=C4Connect; is used to establish the connection to the koha database and that the command lines use C4::Database; and use C4::Input; are inserted at the top of the scripts. The DBI documentation, however, instructs you to use the following database handle command: my $dbh = DBI->connect("dbi:DriverName:db_name", $user, $password) or die "Can't connect to $data_source: $DBI::errstr"; Can someone help us to reconcile these two methods or instruct us on how we should be connecting to the koha database to perform our INSERT commands? Thanks. Larry Currie -- Lawrence W. Currie User Services Librarian California Academy of Sciences Golden Gate Park San Francisco, CA 94118 lcurrie@calacademy.org (415) 750-7108 (415) 750-7106 fax http://www.calacademy.org/research/library/
Hi Larry If you take a look at C4::Database, you'll find that the C4Connect routine returns you $dbh handler using a call similair to your perl below. This of C4Connect as being a wrapper, so that you dont need to replicate the same piece of code in every script that needs to connect to the db. Having said that, C4::Database is in the process of being deprecated and you should use C4::Context. So the syntax is use C4::Context; my $dbh= C4::Context->dbh; Chris On Tue, Mar 25, 2003 at 02:02:07PM -0800, Larry Currie said:
We're developing a script to load data for the biblio, biblioitems, and items tables of the koha MySQL database using DBI and we're wondering what to use for our database handle. I can see that in a number of the koha scripts the command
my $dbh=C4Connect;
is used to establish the connection to the koha database and that the command lines
use C4::Database; and use C4::Input;
are inserted at the top of the scripts.
The DBI documentation, however, instructs you to use the following database handle command:
my $dbh = DBI->connect("dbi:DriverName:db_name", $user, $password) or die "Can't connect to $data_source: $DBI::errstr";
Can someone help us to reconcile these two methods or instruct us on how we should be connecting to the koha database to perform our INSERT commands?
Thanks.
Larry Currie
-- Lawrence W. Currie User Services Librarian California Academy of Sciences Golden Gate Park San Francisco, CA 94118 lcurrie@calacademy.org (415) 750-7108 (415) 750-7106 fax http://www.calacademy.org/research/library/
------------------------------------------------------- This SF.net email is sponsored by: The Definitive IT and Networking Event. Be There! NetWorld+Interop Las Vegas 2003 -- Register today! http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en _______________________________________________ Koha-devel mailing list Koha-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/koha-devel
-- Chris Cormack Programmer 027 4500 789 Katipo Communications Ltd chris@katipo.co.nz www.katipo.co.nz
participants (2)
-
Chris Cormack -
Larry Currie