What is the difference between DBI and DBD?

DBI is database access library, whereas DBDs are "drivers" which are used by DBI to access particular database (eg. there is one DBD for MySQL, another one for PostgreSQL etc). You should use DBI rather than DBDs directly.


From the DBI docs:

               │←−−  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 boxes labeled XYZ Driver and Oracle Driver are DBD modules.

So your code talks to DBI. DBI talks to the appropriate DBD module for your database. The DBD module talks to your database. This results in a single, consistent interface to different databases.

Tags:

Perl

Dbi

Dbd