NAME

NKTI::general::dbconnect - Preparing to multiple database connection.

SYNOPSIS

    use NKTI::general::dbconnect;

    # JSON database config :
    my $json_dbconfig = '{
        "db_host" : "localhost",
        "db_name" : "your_db",
        "db_user" : "your_userdb",
        "db_psas" : "your_passUserDb"
    }';

    # Initialization (example mysql) :
    my $dbh = NKTI::general::dbconnect->mysql($json_dbconfig);

    # For Disconnected :
    $dbh->disconnect();

DESCRIPTION

This module allows the use of multiple database connection database with portable way. The purpose of this module is to be easy to use if you want to use more than one database connection. This Module based DBI.

Modul ini memungkinkan penggunaan database koneksi database dengan cara portable. Tujuan dari modul ini adalah mudah digunakan jika Anda ingin menggunakan lebih dari satu koneksi database.

EXAMPLE 1

    # Example file (db_one.pl) :
    #!/usr/bin/perl
    use strict;
    use warnings;
    use NKTI::general::dbconnect;

    # Database Config 1 :
    my $json_dbconfig1 = '{
        "db_host" : "localhost",
        "db_name" : "your_db1",
        "db_user" : "your_userdb1",
        "db_psas" : "your_passUserDb1"
    }';

    # Database Config 2 :
    my $json_dbconfig2 = '{
        "db_host" : "localhost",
        "db_name" : "your_db1",
        "db_user" : "your_userdb1",
        "db_psas" : "your_passUserDb1"
    }';

    # Establishe Database Interface 1 :
    my $dbh = NKTI::general::dbconnect->mysql($json_dbconfig1);

    # Statement Handle :
    my $sth = $dbh->prepare('SELECT * FROM yourtable');
    $sth->execute();
    my $rv = $sth->rows;
    if ($rv >= 1) {

        # Established Database Interface 2 :
        my $dbh1 = NKTI::general::dbconnect->mysql($json_dbconfig2);

        # Statement Handle :
        my $sth1 = $dbh1->prepare('SELECT * FROM yourtable');
        $sth1->execute();
        my $rv1 = $sth1->rows;
        if ($rv1 >= 1) {
            # true action ...
        } else {
            # false action ...
        }

        # Disconnect and Finishing Query 2 :
        $sth1->finish();
        $dbh1->disconnect();

    } else {
        # false action ...
    }

    # Disconnect and Finishing Query 1 :
    $sth->finish();
    $dbh->disconnect();

EXAMPLE 2

    # Example file (db_two.pl) :
    #!/usr/bin/perl
    use strict;
    use warnings;
    use NKTI::general::dbconnect;

    # Database Config MySQL :
    my $json_dbconfig1 = '{
        "db_host" : "localhost",
        "db_name" : "your_db1",
        "db_user" : "your_userdb1",
        "db_psas" : "your_passUserDb1"
    }';

    # Database Config SQLite :
    my $dbconfig_sqlite = '/your/path/sqlite.db';

    # Establishe Database Interface MySQL :
    my $dbh = NKTI::general::dbconnect->mysql($json_dbconfig1);

    # Statement Handle :
    my $sth = $dbh->prepare('SELECT * FROM yourtable');
    $sth->execute();
    my $rv = $sth->rows;
    if ($rv >= 1) {

        # Established Database Interface SQLite :
        my $dbh1 = NKTI::general::dbconnect->sqlite($dbconfig_sqlite);

        # Statement Handle :
        my $sth1 = $dbh1->prepare('SELECT * FROM yourtable');
        $sth1->execute();
        my $rv1 = $sth1->rows;
        if ($rv1 >= 1) {
            # true action ...
        } else {
            # false action ...
        }

        # Disconnect and Finishing Query SQLite :
        $sth1->finish();
        $dbh1->disconnect();

    } else {
        # false action ...
    }

    # Disconnect and Finishing Query :
    $sth->finish();
    $dbh->disconnect();

EXPLAIN Subroutine mysql

    Description Subroutine :
    ----------------------------------------
    Subroutine for MySQL Database.

    Parameter Subroutine :
    ----------------------------------------
    $get_db_config      =>  JSON Format Database config.

EXPLAIN Subroutine pgsql

        Deskripsi subroutine pgsql() :
        ----------------------------------------
        Subroutne for PostgreSQL Database.

        Parameter subroutine pgsql() :
        ----------------------------------------
        $your_dbconifg      =>  JSON Format Database config.

EXPLAIN Subroutine sqlite

    Description Subroutine :
    ----------------------------------------
    Subroutine for SQLite Database.

    Parameter Subroutine :
    ----------------------------------------
    $fieloc_db          =>  Location of File database SQLite.

SEE ALSO

AUTHOR

Achmad Yusri Afandi, (yusrideb@cpan.org)

COPYRIGHT AND LICENSE

Copyright (c) 2016, Achmad Yusri Afandi, All Rights reserved.

Library for Database Interface.