The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBD::mysql::SimpleMySQL - A simple interface to DBD::mysql

SYNOPSIS

        my %dbinfo = (
                user    => 'user',
                pass    => 'password',
                dsh   => "DBI:mysql:database=DB:host=127.0.0.1:port=3307"
        );

        OR 
        
        my %dbinfo = (
                user            => 'user',
                pass            => 'password',
                database        => 'DB',
                host            => '127.0.0.1',
                port            => '3307'
        );

        $my $dbh = dbconnect(\%dbinfo);

        my $select = ['Passwd.*', 'UsrGrp.UsrGrpName'];
        my $from = ['Passwd'];
        my $joins = [];
        push @{$joins}, join_struct("PasswdHostGrp", "Passwd.PasswdID", "PasswdHostGrp.PasswdID");
        push @{$joins}, join_struct("UsrGrp", "Passwd.PrimaryGroupID", "UsrGrp.UsrGrpID");
        my $wheres = "PasswdHostGrp.HostGrpID IN ('group1', 'group2')";
                
        my $arrayref = dbselect_array($dbh, build_select($select, $from, $joins, $wheres, 0));

EXAMPLE

        #!/usr/bin/perl -w
        #
        use strict;
        use DBD::mysql::SimpleMySQL qw/:all/;

        my %dbinfo = (
                user            => 'user',
                pass            => 'password',
                database        => 'DB',
                host            => '127.0.0.1',
                port            => '3307'
        );

        $my $dbh = dbconnect(\%dbinfo);

        my $select = ['Passwd.*', 'UsrGrp.UsrGrpName'];
        my $from = ['Passwd'];
        my $joins = [];
        push @{$joins}, join_struct("PasswdHostGrp", "Passwd.PasswdID", "PasswdHostGrp.PasswdID");
        push @{$joins}, join_struct("UsrGrp", "Passwd.PrimaryGroupID", "UsrGrp.UsrGrpID");
        my $wheres = "PasswdHostGrp.HostGrpID IN ('group1', 'group2')";
                
        my $arrayref = dbselect_array($dbh, build_select($select, $from, $joins, $wheres, 0));


        my $i = 1;
        for my $row (@{$arrayref}) {
                print "Row $i\n";
                for my $key (keys(%{$row})) {
                        print "\t$key = ${$row}{$key}\n";
                }
                $i++;
        }
        

DESCRIPTION

DBD::mysql::SimpleMySQL is an extention of the DBI mysql driver. It simplifies getting the data you want out of your DB. I wrote it because I found that everytime I put together a DBI based app I ended up writing these functions anyway.

Public Methods dbinsert dbconnect($) Takes a hash ref, return a DBI database handle.

dbselect($$) Takes a DBI db handle and a MySQL query string.

dbselect_arrayref($$) Takes a DBI db handle and a MySQL query string.

dbinsert dbupdate($$$$) Takes a DBI db handle, table name string, a hash ref of Columns to update including an "ID" column, and the "ID" column string

dbdo($$) Takes a DBI db handle and a SQL command string. This string is pretty much passed directly to $dbh->do

where_struct($$$) Takes a key, type and value argument. Key is the column name or function in a where clause. Type is the comparison, "LIKE", "IN", "=" etc. Value is the value. "WHERE Key = Value." Returns a reference to be used in "build_wheres"

join_struct($$$) Takes a table, tableid and joinid. Table is the table to join to query. Tableid is the key to join the table on. "JOIN table ON tableid = joinid." Joinid is the key to join the table on. "JOIN table ON tableid = joinid." Returns a reference to be used in "build_joins"

build_joins($) Takes a "join_struct" reference. Builds a LEFT JOIN query string. OR Takes a JOIN string directly including the "JOIN". Returns a LEFT JOIN string to be passed to "build_*"

build_wheres($) Takes a reference to an array of "where_struct" references. Builds a WHERE query string. OR Takes a WHERE string directly not including the "WHERE". Returns a WHERE string to be passed to "build_*"

build_select($$$$$)

build_insert($$)

build_delete($$$)

find_dup($$$$)

AUTHOR

Jacob Boswell

COPYRIGHT

DBD::mysql::SimpleMySQL is Copyright(c) 2004 Jacob Boswell. All rights reserved You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 560:

=back without =over