DBIx::CGI - Easy to Use DBI interface for CGI scripts |
DBIx::CGI - Easy to Use DBI interface for CGI scripts
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');
DBIx::CGI is an easy to use DBI interface for CGI scripts. Currently only the Pg, mSQL and mysql drivers are supported.
$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 racke@linuxia.net aF3xD4_i));
The required parameters are a the CGI manpage 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.
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.
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 %s will 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");
print $dbi_interface -> cgi() -> header();
Returns the CGI object passed to the constructor.
Stefan Hornburg, racke@linuxia.net Dennis Schön, dschoen@rio.gt.owl.de
perl(1), CGI(3), DBI(3), DBD::Pg(3), DBD::mysql(3), DBD::msql(3).
DBIx::CGI - Easy to Use DBI interface for CGI scripts |