NAME

MySQL::Easy - Perl extension to make your base code kinda pretty.

SYNOPSIS

use MySQL::Easy;

my $dbo = new MySQL::Easy("stocks");

my $symbols = $dbo->firstcol(
    qq( select symbol from ohlcv where symbol != ?),
    "msft"
);

for(@$symbols) {
    my $q = $dbo->ready("select * from ohlcv where symbol=?");
    my @a;

    execute $q;
    print "@a" while @a = fetchrow_array $q;
}

DESCRIPTION

I don't remember how I used to live without this...
I do like the way DBI and DBD work, but I wanted something
_slightly_ prettier... _slightly_ handier.

Here's the functions MySQL::Easy provides:

$dbo = new MySQL::Easy( $db_name, $trace );
    # $db_name is the name of the database you're connecting to...
    # If you don't pick anything, it'll pick "test" for you.
    # $trace is a 1 or false, ... it's the DBI->trace() ...

$dbo->do("sql statement bind=? bind=?", $bind1, $bind2);
    # this immediately executes the sql with the bind vars
    # given.  You can pas in a statement handle
    # instead of the string... this is faster if you're going
    # to use the sql over and over.  Returns a t/f like you'd
    # expect.  (i.e. $dbo->do("stuff") or die $dbo->errstr);

$dbo->lock("table1", "table2", "table3");
    # MySQL::Easy uses only write locks.  Those are the ones
    # where nobody can read or write to the table except the
    # locking thread.  If you need a read lock, let Jet know.
    # Most probably though, if you're using this, it's a
    # smaller app, and it doesn't matter anyway.
$dbo->unlock;

$sth = $dbo->ready("Sql Sql Sql=? and Sql=?");
    # returns a DBI statement handle...
    # $sth->execute($bindvar); $sth->fetchrow_hashref; etc...

$arr = $dbo->firstcol("select col from tab where x=? and y=?", $x, $y)
    # returns an arrayref of values for the sql.
    # You know, print "val: $_\n" for @$arr;
    # very handy...

$id = $dbo->last_insert_id;
    # self explainatory?

$dbo->trace(1); $dbo->do("sql"); $dbo->trace(0);
    # turns the DBI trace on and off.

$dbo->errstr
    # returns an error string for the last error on the
    # thread...  Same as a $sth->errstr.  It's actually
    # described in DBI

$dbo->set_host($h); $dbo->set_user($U); $dbo->set_pass($p);
    # The first time you do a do/ready/firstcol/etc,
    # MySQL::Easy connects to the database.  You may use these
    # set functions to override values found in your ~/.my.cnf
    # for user and pass.  MySQL::Easy reads _only_ the user
    # and pass from that file.  The host name will default to
    # "localhost" unless explicitly set.  Also, it will die on
    # a fatal error if the user or pass is false and the
    # ~/.my.cnf cannot be opened.

AUTHOR

Jettero Heller <japh@voltar-confed.org>

Jet is using this software in his own projects...
If you find bugs, please please please let him know. :)

Actually, let him know if you find it handy at all.
Half the fun of releasing this stuff is knowing 
that people use it.

SEE ALSO

perl(1), DBI(3)