What is the difference between DBI and DBD?

Can someone shed light on what exactly DBI and DBD are? When you need to use one of them and use one of them.

+7
source share
5 answers

DBI is a database access library, while DBDs are the β€œdrivers” that DBIs use to access a particular database (for example, there is one DBD for MySQL, another for PostgreSQL, etc.). You must use DBI directly, not DBD.

+20
source

From 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
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚   β”œβ”€β”€ βˆ™βˆ™βˆ™
                      β””β”€β”€β”€β”˜

Boxes with inscriptions XYZ Driverand Oracle Driverare DBD modules.

, DBI. DBI DBD . DBD . , .

+16

DBI - . DBD - .

+9

DBI . DBD .

, (DBI). , , . DBI DBD , . DBD, . , , , . . ( .)

+4

Use them together. For example, MySQL :

use DBI;

$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $user, $password);

$sth = $dbh->prepare("SELECT * FROM foo WHERE bla");
$sth->execute;

If you are talking to Oracle instead , you can only leave the $data_sourceargument with the change DBI::connect:

$dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid", $user, $password);
+1
source

All Articles