Reference

DBIx::CGI(3pm)

Easy to Use DBI interface for CGI scripts

NAME

DBIx::CGI - Easy to Use DBI interface for CGI scripts

SYNOPSIS

  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');

DESCRIPTION

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 %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");

cgi
  print $dbi_interface -> cgi() -> header();

Returns the CGI object passed to the constructor.

AUTHORS

Stefan Hornburg, [email protected] Dennis Schön, [email protected]

SEE ALSO

perl(1), CGI(3), DBI(3), DBD::Pg(3), DBD::mysql(3), DBD::msql(3).

History