DBIx::CGI3pm
Easy to use dbi interface for cgi scripts
Usage
use CGI;my $cgi = new CGI;use DBIx::CGI;my $dbi_interface = new DBIx::CGI ($cgi, qw(Pg template1));
$dbi_interface -> insert ('transaction',id => serial ('transaction', 'transactionid'),time => \$dbi_interface -> now);
$dbi_interface -> update ('components', "table='ram'", price => 100);$dbi_interface -> makemap ('components', 'id', 'price');$components = $dbi_interface -> rows ('components');$components_needed = $dbi_interface -> rows ('components', 'stock = 0');
Overview
DBIx::CGI is an easy to use DBI interface for CGI scripts. Currently only the Pg, mSQL and mysql drivers are supported.
Creating a new dbi interface object
$dbi_interface = new DBIx::CGI ($cgi qw(Pg template1));$dbi_interface = new DBIx::CGI ($cgi qw(Pg template1 racke));$dbi_interface = new DBIx::CGI ($cgi qw(Pg template1 racke aF3xD4_i));$dbi_interface = new DBIx::CGI ($cgi qw(Pg template1 [email protected] aF3xD4_i));
The required parameters are a CGI object, the database driver and the database name. Additional parameters are the database user and the password to access the database. To specify the database host use the USER@HOST notation for the user parameter.
Error handling
sub fatal {my ($statement, $err, $msg) = @_;die ("$0: Statement \"$statement\" failed (ERRNO: $err, ERRMSG: $msg)\n");}$dbi_interface -> install_handler (\&fatal);
If any of the DBI methods fails, either die will be invoked or an error handler installed with install_handler will be called.
- view table [name value ...]
-
foreach my $table (sort $dbi_interface -> tables){print $cgi -> h2 ('Contents of ', $cgi -> code ($table));print $dbi_interface -> view ($table);}Produces HTML code for a table displaying the contents of the database table table. This method accepts the following options as name/value pairs:
order: Which column to sort the row after.column_link: URI for the column names. A%swill be replaced by the column name.limit: Maximum number of rows to display.where: Display only rows matching this condition.print $dbi_interface -> view ($table,order => $cgi -> param ('order') ⎪⎪ '',column_link => $cgi->url(). "&order=%s",where => "price > 0");
- cgi
-
print $dbi_interface -> cgi() -> header();Returns the CGI object passed to the constructor.
Releases
3 releases since Debian 2.2 (Potato); the text changed 2 times.