The DBI is a database access module for the Perl programming language. It defines a set of methods, variables, and conventions that provide a consistent database interface, independent of the actual database being used.

It is important to remember that the DBI is just an interface. The DBI is a layer of "glue" between an application and one or more database driver modules. It is the driver modules which do most of the real work. The DBI provides a standard interface and framework for the drivers to operate within.

This document often uses terms like references, objects, methods. If you're not familiar with those terms then it would be a good idea to read at least the following perl manuals first: perlreftut, perldsc, perllol, and perlboot.
Architecture of a DBI Application

             |<- Scope of DBI ->|
                  .-.   .--------------.   .-------------.
  .-------.       | |---| XYZ Driver   |---| XYZ Engine  |
  | Perl  |       | |   `--------------'   `-------------'
  | script|  |A|  |D|   .--------------.   .-------------.
  | using |--|P|--|B|---|Oracle Driver |---|Oracle Engine|
  | DBI   |  |I|  |I|   `--------------'   `-------------'
  | API   |       | |...
  |methods|       | |... Other drivers
  `-------'       | |...
                  `-'

The API, or Application Programming Interface, defines the call interface and variables for Perl scripts to use. The API is implemented by the Perl DBI extension.

Specific drivers are implemented for each different type of database and actually perform the operations on the databases

Above is the description I copied from CPAN DBI DESCRIPTION , which clearly say that Perl DBI is used to interact with databases, DBI stands for DataBase Independent Interface. So, the API is quite generic on top of different DBI drivers, make things easier for perl developer.


I have an article showed some functions I wrote for DBD::mysql useful code examples

So, not necessary to repeat everything again, here I just show few functions related with pg driver, Similarily, you can make easily change to another type of DB by changing driver like below.

Function to connect to db

###############################################################################
# SUB:          dbConninit
# PURPOSE:      get sharable db connection handle to postgresql
#
# ARGS:
#
# NOTES:
# RETURNS:      $dbh - databse connector
###############################################################################
sub dbConninit
{
  my $cnt = 0;
  my $sleeptime = 10;
  my $connStr = 'DBI:Pg:dbname='.$g_dbparams{"db"}.';host='.$g_dbparams{"host"};

  do {
    if( $cnt > 0 ) {
      logMsg( "Problem connecting to postgresql: sleeping.", _LOG );
      $sleeptime += $cnt*5;
      sleep $sleeptime ;
    }
    $cnt++;
    $g_dbh = DBI->connect( $connStr, $g_dbparams{"user"}, $g_dbparams{"pass"},
     {RaiseError => 0, PrintError => 0} );
  } while( ! $g_dbh and $cnt <= 10 );

  if( ! $g_dbh ) {
    dbErr( "Cannot connect to database.", "die" );
  }
  return($g_dbh);
}

Once DB is connected, all other db functions, like select, delete, update and create etc.. All can be done in API, for ready for used perl db functions, see my perl mysql examples