Koha::Database
use Koha::Database; my $schema = Koha::Database->schema();
$schema = Koha::Database->new->schema; FIXME: It is useless to have a Koha::Database object since all methods below act as class methods Koha::Database->new->schema is exactly the same as Koha::Database->schema We should use Koha::Database->schema everywhere and remove the `new` method
Returns a database handler without loading the DBIx::Class schema.
$schema = Koha::Database->schema; $schema = Koha::Database->schema({ new => 1 });
Returns a database handle connected to the Koha database for the current context. If no connection has yet been made, this method creates one, and connects to the database.
This database handle is cached for future use: if you call $database->schema
twice, you will get the same handle both times. If you need a second database handle, use &new_schema
and possibly &set_schema
.
$schema = $database->new_schema;
Creates a new connection to the Koha database for the current context, and returns the database handle (a DBI::db
object).
The handle is not saved anywhere: this method is strictly a convenience function; the point is that it knows which database to connect to so that the caller doesn't have to know.
$my_schema = $database->new_schema; $database->set_schema($my_schema); ... $database->restore_schema;
&set_schema
and &restore_schema
work in a manner analogous to &set_context
and &restore_context
.
&set_schema
saves the current database handle on a stack, then sets the current database handle to $my_schema
.
$my_schema
is assumed to be a good database handle.
$database->restore_schema;
Restores the database handle saved by an earlier call to $database->set_schema
.
my $dbd_driver_name = Koha::Database::db_scheme2dbi($scheme);
This routines translates a database type to part of the name of the appropriate DBD driver to use when establishing a new database connection. It recognizes 'mysql' and 'Pg'; if any other scheme is supplied it defaults to 'mysql'.
None by default.
Chris Cormack, <chrisc@catalyst.net.nz>