This code just open a connection to a mysql database, and then it close it:
my $dbh = DBI->connect("dbi:mysql:test", "root", "password") ||
die "Connection error: $DBI::errstr\n";
There is something interesting even in these few lines.
First of all we see that to start a connection we call the connect() function in the DBI package passing three paramenters representing the database to which we are about to connect (protocol and database name), the database user and its password.
If connect() fails, we let our script die, showing the error message that is stored in DBI::errstr.
Finally (!) we close the connection calling the disconnect() method on the dbh object resulting by the connect() call.