BW::DB - Normalized database routines
use BW::DB; my $errstr; my $db = BW::DB->new( connect => "database:host:3306:user:password" ); error($errstr) if (($errstr = $db->error)); my $db = BW::DB->new( dsn => 'DBI:mysql:database=database;mysql_socket=/tmp/mysql2.sock", user => "me", password => "foo!bar" ); error($errstr) if(($errstr = $db->error)); my $db = BW::DB->new( database => "database", host => "host", port => "3306", user => "user", password => "pass"); error($errstr) if (($errstr = $db->error)); # experimental SQLite support ... my $db = BW::DB->new(dbengine => "SQLite", dbname => "dbfile"); error($errstr) if (($errstr = $db->error));
Constructs a new DB object. Connect string is in the format:
database:host:port:user:password
... or for experimental SQLite support:
SQLite:dbfile
Returns a blessed DB object reference. Returns VOID if an object cannot be created. If the object is constructed but there is an error connecting to the database, the object reference is returned and $db->error is set.
Alternately you can call new() with separate parameters for the database connection thusly:
my $db = BW::DB->new( database => "database", host => "host", port => "3306", user => "user", password => "pass" );
my $db = BW::DB->new( dbengine => "SQLite", dbname => "dbfile" );
If your database is listening on a named pipe you can connect using a DBI DSN like this:
my $db = BW::DB->new( dsn => "DBI:mysql:database=database;mysql_socket=/tmp/mysql2.sock", user => "me", password => "foo!bar" ); error($errstr) if(($errstr = $db->error));
Calls DBD::do for queries that don't return data, like INSERT or DELETE. Returns SUCCESS or FAILURE.
Performs the query with the bind values and returns an arrayref where each element in the array is a hashref with a row of data returned from the query. Keys are set to column names.
Returns FAILURE and sets $db->error if a DBI error was encountered.
Performs the query with the bind values and returns an arrayref where each element in the array is a scalar value from the first column returned from the query.
Performs the query with the bind values and returns a scalar with a single value from the query. The query should return a single value from a single column.
Performs an insert into table with the names/values in $hashref. Use the insert_id method to get the value of any auto_increment field.
Returns SUCCESS or FAILURE (and sets $db->error).
Returns the value of any auto_increment field from the last insert operation.
Performs a "describe" and returns TRUE or FALSE.
Returns and clears the object error message.
Written by Bill Weinman <http://bw.org/>.
Copyright (c) 1995-2010 The BearHeart Group, LLC
See HISTORY file.
To install BW::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BW::DB
CPAN shell
perl -MCPAN -e shell install BW::DB
For more information on module installation, please visit the detailed CPAN module installation guide.