NAME
DBIx::DBO - An OO interface to SQL queries and results.
VERSION
Version 0.01
SYNOPSIS
use DBIx::DBO;
# Create the DBO
my $dbo = DBIx::DBO->connect('DBI:mysql:my_db', 'me', 'mypasswd') or die $DBI::errstr;
# Create a "readonly" connection - useful for a slave database
$dbo->connect_readonly('DBI:mysql:my_db', 'me', 'mypasswd') or die $DBI::errstr;
# Start with a Query object
my $query = $dbo->query('my_table');
# Find records with an 'o' in the name
$query->where('name', 'LIKE', '%o%');
# And with an id that is less than 500
$query->where('id', '<', 500);
# Exluding those with an age range from 20 to 29
$query->where('age', 'NOT BETWEEN', [20, 29]);
# Return only the first 10 rows
$query->limit(10);
# Fetch the rows
while (my $row = $query->fetch) {
# Use the row as an array reference
printf "id=%d name=%s status=%s\n", $row->[0], $row->[1], $row->[4];
# Or as a hash reference
print 'id=', $row->{id}, "\n", 'name=', $row->{name};
# Update/delete rows
$row->update(status => 'Fired!') if $row->{name} eq 'Harry';
$row->delete if $record->{id} == 27;
}
# Join tables (INNER JOIN)
my ($query, $table1, $table2, $table3) = $dbo->query('my_table', 't2', 'third');
$query->join_on($table2 ** 'parent_id', '=', $table3 ** 'child_id');
# Join tables (LEFT JOIN)
my ($query, $table1) = $dbo->query('my_table');
my $table2 = $query->join_table('another_table', 'LEFT');
$query->join_on($table2 ** 'parent_id', '=', $table1 ** 'child_id');
DESCRIPTION
This module provides a convenient and efficient way to access a database. It can construct queries for you and returns the results in an easy to use method.
FUNCTIONS
config
$global_setting = DBIx::DBO->config($option)
DBIx::DBO->config($option => $global_setting)
Get or set the global config settings. When setting an option, the previous value is returned.
connect
$dbo = DBIx::DBO->connect($data_source, $username, $password, \%attr)
or die $DBI::errstr;
Takes the same arguments as DBI->connect for a read-write connection to a database. It returns the DBIx::DBO object if the connection succeeds or undefined on failure.
connect_readonly
Takes the same arguments as connect
for a read-only connection to a database. It returns the DBIx::DBO object if the connection succeeds or undefined on failure.
Both connect & connect_readonly can be called on a $dbo object without that respective connection to have a DBO with both read-write and read-only connections.
my $dbo = DBIx::DBO->connect($master_dsn, $username, $password, \%attr)
or die $DBI::errstr;
$dbo->connect_readonly($slave_dsn, $username, $password, \%attr)
or die $DBI::errstr;
AUTHOR
Vernon Lyon, <vlyon at cpan.org>
BUGS
Please report any bugs or feature requests to bug-dbix-dbo at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-DBO. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DBIx::DBO
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2009 Vernon Lyon, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.