<<

NAME

Koha::Database

SYNOPSIS

  use Koha::Database;
  my $schema = Koha::Database->schema();

FUNCTIONS

new

    $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

dbh

    Returns a database handler without loading the DBIx::Class schema.

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.

new_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.

set_schema

  $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.

restore_schema

  $database->restore_schema;

Restores the database handle saved by an earlier call to $database->set_schema.

get_schema_cached

flush_schema_cache

db_scheme2dbi

    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'.

EXPORT

None by default.

AUTHOR

Chris Cormack, <chrisc@catalyst.net.nz>

<<