CTK::DBI - Database independent interface for CTKlib
Version 2.31
use CTK::DBI; # Enable debugging # $CTK::DBI::CTK_DBI_DEBUG = 1; # MySQL connect my $mso = CTK::DBI->new( -dsn => 'DBI:mysql:database=TEST;host=192.168.1.1', -user => 'login', -pass => 'password', -connect_to => 5, -request_to => 60 #-attr => {}, #-prepare_attr => {}, #-debug => 1, ); my $dbh = $mso->connect or die($mso->error); die($mso->error) if $mso->error; # Table select (as array) my @result = $mso->table($sql, @inargs); # Table select (as hash) my %result = $mso->tableh($key, $sql, @inargs); # $key - primary index field name # Record (as array) my @result = $mso->record($sql, @inargs); # Record (as hash) my %result = $mso->recordh($sql, @inargs); # Field (as scalar) my $result = $mso->field($sql, @inargs); # SQL my $sth = $mso->execute($sql, @inargs); ... $sth->finish;
For example: print($mso->field("select sysdate() from dual"));
# MySQL connect my $mso = CTK::DBI->new( -dsn => 'DBI:mysql:database=TEST;host=192.168.1.1', -user => 'login', -pass => 'password', -connect_to => 5, -request_to => 60 #-attr => {}, #-prepare_attr => {}, #-debug => 1, );
Create the DBI object
my $dbh = $mso->connect;
See "dbh"
my $dbh = $mso->dbh;
Returns DBH object (DB handler of DBI)
my $rc = $mso->disconnect;
Forced disconnecting. Please not use this method
die $mso->error if $mso->error;
Returns error string
# SQL my $sth = $mso->execute($sql, @inargs); ... $sth->finish;
Executing the SQL
# Fields (as scalar) my $result = $mso->field($sql, @inargs);
Get (select) field from database as scalar value
# Record (as array) my @result = $mso->record($sql, @inargs); # Record (as hash) my %result = $mso->recordh($sql, @inargs);
Get (select) record from database as array or hash
# Table select (as array) my @result = $mso->table($sql, @inargs); # Table select (as hash) my %result = $mso->tableh($key, $sql, @inargs); # $key - primary index field name
Get (select) table from database as array or hash
See Changes file
Changes
Debug mode flag. Default: 0
General error string
DBI
See TODO file
TODO
* none noted
Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE file and https://dev.perl.org/licenses/
LICENSE
To install CTK, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CTK
CPAN shell
perl -MCPAN -e shell install CTK
For more information on module installation, please visit the detailed CPAN module installation guide.