Connection to MySQL
Once MySQL database is installed, and at least one
database is created (example "academia") with some tables,
we can perform the following to make connection:
To get connected with MySQL database "academia", we use
the following code:
#!C:/Perl/bin/perl
use DBI;
use strict;
my $driver = "mysql";
my $database = "academia";
my $dsn = "DBI:$driver:database=$database";
my $userid = "root";
my $password = "The_password";
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
$dsn: Database source name
$dbh : Database handle object
Once the connection is established, the "Database Handle"
is returned and saved into $dbh. Otherwise, $DBI::errstr will
return an error string.
|