DBIx::DBH - helper for DBI connection( data)?
use DBIx::DBH; my $config = DBIx::DBH->new ( user => $user, pass => $pass, dsn => { driver => 'mysql', port => 3306 }, attr => { RaiseError => 1 } ); $config->for_skinny ; # outputs data structure for DBIx::Skinny setup $config->for_rose_db; # outputs data structure for Rose::DB::register_db $config->for_dbi; # outputs data structure for DBI connect() $config->dbh; # makes a database connection with DBI $config->conn; # makes a DBIx::Connector instance
DBIx::DBH allows you to specify the DBI dsn ( ""connect" in DBI ) as a hash ref instead of a string. A hashref is a more viable structure in a few cases:
working with Rose::DB
"Registering_data_sources" in Rose::DB::Tutorial shows that Rose::DB expects the dsn information as discrete key-value pairs as opposed to a string. The ->for_rose_db method takes the DBIx::DBH instance and returns a hash array which can be consumed by "register_db" in Rose::DB
->for_rose_db
NOTE: A working example for using DBIx::DBH to connect in Rose::DB::Object is here
working with DBIx:Skinny
Unless you pass in a living, breathing DBI database handle, DBIx::Skinny expects the connection information to be passed in key-value pairs. The ->for_skinny addresses this API demand.
->for_skinny
NOTE: A working example for using DBIx::DBH to connect in DBIx::Skinny is here
programmatic connection attempts
It is much easier to manipulate a hash programmatically if you need to systematically modify it as part of a series of connection attempts.
high-level structure
Whether you are talking about configuration file utilities or form data, most data from these modules comes back directly as hashes. So you have a more direct way of shuttling data into a database connection if you use this module:
my $dbh = DBIx::DBH->new(map { $_ => $cgi->param($_) } grep(/dsn|user|pass/, keys %{$cgi->Vars})->dbh;
Instead of a bunch of string twiddling.
Returns data in a format suitable for calling DBI->connect.
DBI->connect
Actually constructs a DBI database handle via DBI->connect.
Actually constructs a DBIx::Connect database handle.
Returns data in a format suitable for using DBIx::Skinny.
Returns data in a format suitable for using Rose::DB
A procedural version of DBIx::DBH is still available as DBIx::DBH::Legacy.
The file DBH.pm in DBIx::Cookbook is an example of deriving a connection class from DBIx::DBH -
http://github.com/metaperl/dbix-cookbook/blob/master/lib/DBIx/Cookbook/DBH.pm
Config::DBI
DBIx::Connect
DBIx::Password
Ima::DBI
http://perlmonks.org/?node_id=835894
Terrence Brannon, metaperl@gmail.com
metaperl@gmail.com
thanks to Khisanth, Possum and DrForr on #perl-help
http://github.com/metaperl/dbix-dbh
Copyright (C) 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.
To install DBIx::DBH, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::DBH
CPAN shell
perl -MCPAN -e shell install DBIx::DBH
For more information on module installation, please visit the detailed CPAN module installation guide.