Question

I'm using DBIx::Simple with SQL::Abstract in my application. This is database connection code:

my $nms_host    = 'mysql.server.com';
my $nms_base    = 'mydb';
my $nms_user    = 'myuser';
my $nms_pass    = 'password123';
my $nms_dsn     = "DBI:mysql:$nms_base:$nms_host";

# Initialize connection
# NMS
my $db_nms = DBIx::Simple->connect($nms_dsn, $nms_user, $nms_pass, {
    RaiseError => 1,
    mysql_enable_utf8 => 1
}) or die DBIx::Simple->error;
$db_nms->abstract = SQL::Abstract->new(
    case    => 'lower',
    logic   => 'and'
);

For now I need to use DBIx::Connector but I don't understand how I should make a connection.

Was it helpful?

Solution

DBIx::Connector creates your database handle, which you can then pass directly to DBIx::Simple. So, for your purposes, something like this should work:

#!/usr/bin/env perl

use strict;
use warnings;

use DBIx::Connector;
use DBIx::Simple;

my $nms_host    = 'mysql.server.com';
my $nms_base    = 'mydb';
my $nms_user    = 'myuser';
my $nms_pass    = 'password123';
my $nms_dsn     = "DBI:mysql:$nms_base:$nms_host";

my $conn = DBIx::Connector->new(
    $nms_dsn,
    $nms_user,
    $nms_pass,
    {   RaiseError        => 1,
        mysql_enable_utf8 => 1,
    }
);

my $simple = DBIx::Simple->connect( $conn->dbh );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top