DBIx::DBH - Perl extension for simplifying database connections |
connect(%params)
connect_data(%params)
connect_data(%params)
form_dsn(%params)
DBIx::DBH - Perl extension for simplifying database connections
use DBIx::DBH;
my %opt = (tty => 1) ; my %dat = ( driver => 'Pg', dbname => 'db_terry', user => 'terry', password => 'markso' );
my $dbh = DBIx::DBH->connect(%dat, %opt) ;
DBIx::DBH is designed to facilitate and validate the process of creating DBI database connections. It's chief and unique contribution to this set of modules on CPAN is that it forms the DSN string for you, regardless of database driver. Another thing about this module is that it takes a flat Perl hash as input, making it ideal for converting HTTP form data and or config file information into DBI database handles. It also can form DSN strings for both major free databases and is subclassed to support extension for other databases.
DBIx::DBH provides rigorous validation on the input parameters via the Params::Validate manpage. It does not allow parameters which are not defined by the DBI or the database driver driver into the hash.
I provides support for MySQL, Postgres and Sybase (thanks to Rachel Richard for the Sybase support).
connect(%params)
%params
requires the following as keys:
%params
can have the following optional parameters
%params
can also have parameters specific to a particular database
driver. See
the DBIx::DBH::Sybase manpage,
the DBIx::DBH::mysql manpage and the DBIx::DBH::Pg manpage for additional parameters
acceptable based on database driver.
connect_data(%params)
connect_data
takes the same arguments as connect()
but returns
a list of the 4 arguments required by the the DBI manpage connect()
function. This is useful for working with modules that have an
alternative connection syntax such as the DBIx::AnyDBD manpage or
Alzabo.
connect_data(%params)
connect_data
takes the same arguments as connect()
but returns
a list of the 4 arguments required by the the DBI manpage connect()
function. This is useful for working with modules that have an
alternative connection syntax such as the DBIx::AnyDBD manpage or
Alzabo.
form_dsn(%params)
form_dsn
takes the same arguments as connect()
but returns
only the properly formatted DSN string. This is also
useful for working with modules that have an
alternative connection syntax such as the DBIx::AnyDBD manpage or
Alzabo.
Simply add a new driver with a name of DBIx::DBH::$Driver
, where
$Driver
is a valid DBI driver name.
> > It would be nice if the parameter validation info was exposed in some > way, so that an interactive piece of software can ask a user which > driver they want, then query your module for a list of supported > parameters, then ask the user to fill them in. (Perhaps move the hash > of validation parameters to a new method named valid_params, and then > have connect_data call that method and pass the return value to > validate?)
Terrence Brannon, <bauhaus@metaperl.com>
Sybase support contributed by Rachel Richard.
Mark Stosberg did all of the following:
I've attached a patch which refactors the code to address this.
Rather than relying on a hardcoded list, it tries to 'require' the driver, or dies with a related error message.
This could lower your own maintenance effort, as others can publish additional drivers directly without requiring a new release of DBIx::DBH for it to work.``
Substantial suggestions by M. Simon Ryan Cavaletto.
Copyright (C) 2004 by Terrence Brannon
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
DBIx::DBH - Perl extension for simplifying database connections |