NAME

Generic::UI::DB::Mysql - Mysql Database Backend Module for Generic::U/p

SYNOPSIS

use Generic::UI::DB::Mysql; # load the module my $db = new Generic::UI::DB::Mysql(%options); # create new object my %users = $db->get_multiple();

DESCRIPTION

This module is an internal perl module used by both the CGI and the server programs to simplify database access and to provide a higher level view on the database. It also hides the database internals. This makes it much easier to extend the database structure or to migrate the whole application to another DBMS, for example oracle or the like.

All parameters or hash keys correspond to table fields defined in the database structures. So you need to know about it anyway. And if you change existing fields in the database structure without providing code to be backward compatible you will get much trouble. You've been warned.

METHODS

new()

new() creates a new Generic::UI::DB::mysql object. All parameters must be provided as a hash.

The following parameters are available:

rollback()

   params:
  returns:

commit()

   params:
  returns:

select()

Method used to do selects.

A returns an array of hashrefs per record.

Parameters in this order:

Examples:

$db->select("SELECT * FROM blah WHERE idx = ?", [ 123 ]); $db->select("SELECT * FROM blah", { idx => 4, username => "ha%" }, "ORDER by username" );

insert()

Method used to do inserts.

Returns nothing.

Parameters in this order:

Examples:

$db->insert("INSERT INTO blah SET idx = ?, user = ?", [ 1443, "scip" ] ); $db->insert("INSERT INTO blah", { idx => 1443, user => "scip" } );

update()

Method used to do updates.

Returns nothing.

Parameters in this order:

Examples:

$db->update("UPDATE blah SET password = ? WHERE idx = ?", [ "glubbibulgah", 1443 ] ); $db->update("UPDATE blah", { password => "glubbibulgah", idx => 1443 } );

delete()

Method used to do deletes.

Returns nothing.

Parameters in this order:

Examples:

$db->insert("DELETE FROM blah WHERE idx = ?", [ 1443 ] );

WRAPPER METHODS

Those methods are for easier access to the database. Using these wrappers avoids using SQL statements at all.

Since the parameters always have the same meaning they are all described here.

Possible parameters:

get_single()

Get a single entry of the db.

Parameters:

$table, $param

Returns:

Hash.

get_max()

Get the maximum value of a certain field in a table.

Parameters:

$table, $field

Returns:

Integer.

get_multiple()

Get multiple entries of the db.

Parameters:

$table, $order, $param

Returns:

Array of hash references.

add_entry()

Add an entry to the db.

Parameters:

$table, $param

Returns:

Nothing.

modify_entry()

Update an existing entry to the db. $param must contain a key idx for this to work.

Parameters:

$table, $param

Returns:

Nothing.

remove_entry()

Remove an existing entry from the db.

Parameters:

$table, $param

Returns:

Nothing.

COPYRIGHT

Copyright (C) 2002 T.L..