You should make sure that module DBI has been installed on your pc, then follow the bellow steps:
use DBI;
my $driver = "MyDriver";
my $database = "DB_name";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "your_user_ID";
my $password = "your_password";
my $tablename = "your_table";
my $dbh = DBI->connect($dsn, $userid, $password);
my $query = $dbh->prepare("Your DB query");
Ex:
$my_query = qq/SELECT * FROM table WHERE column1 = 2/;
my $query = $dbh->prepare($my_query);
We can also use variable in the query, like below:
my $table_name = "table";
my $filter_value = 2;
$my_query = qq/SELECT * FROM $table_name WHERE column1 = $filter_value/;
$query->execute();
*Note: To avoid injection attack, you should use placeholders ?
instead of put your variable in the query.
Ex: you want to show the all data from 'table' where column1=$value1 and column2=$value2:
my $query = $dbh->prepare("SELECT * FROM table WHERE column1 = ? AND column2 = ?;");
$query->execute($value1, $value2);
my @row = $query->fetchrow_array();
store data as array
or
my $ref = $sth->fetchrow_hashref();
store data as hash reference
$sth->finish;
$dbh->disconnect();