NAME
WWW::MLite::Store::DBI - Database independent interface for WWW::MLite on CTK::DBI based
VERSION
Version 1.01
SYNOPSIS
use WWW::MLite::Store::DBI;
# MySQL connect
my $mysql = new WWW::MLite::Store::DBI (
-mlite => $mlite, # OPTIONAL
-dsn => 'DBI:mysql:database=TEST;host=192.168.1.1',
-user => 'login',
-pass => 'password',
-connect_to => 5,
-request_to => 60
-attr => {
mysql_enable_utf8 => 1,
RaiseError => 0,
PrintError => 0,
},
); # See CTK::DBI
# MySQL connect (old style, without DSN)
my $mysql = new WWW::MLite::Store::DBI (
-mlite => $mlite, # OPTIONAL
-driver => 'mysql', # Driver name. See DBI module
# Available drivers:
# CSV, DBM, ExampleP, File, Gofer, ODBC, Oracle,
# Pg, Proxy, SQLite, Sponge, mysql
-host => '192.168.1.1',
-port => '3306', # default
-database => 'TEST',
-user => 'login',
-pass => 'password',
-attr => {
mysql_enable_utf8 => 1,
RaiseError => 0,
PrintError => 0,
},
);
my $dbh = $mysql->connect;
my $pingstat = $mysql->ping if $mysql;
$mysql->reconnect() unless $pingstat;
# Table select (as array)
my @result = $mysql->table($sql, @inargs);
# Table select (as hash)
my %result = $mysql->tableh($key, $sql, @inargs); # $key - primary index field name
# Record (as array)
my @result = $mysql->record($sql, @inargs);
# Record (as hash)
my %result = $mysql->recordh($sql, @inargs);
# Fiels (as scalar)
my $result = $mysql->field($sql, @inargs);
# SQL/PL-SQL
my $sth = $mysql->execute($sql, @inargs);
...
$sth->finish;
DESCRIPTION
Database independent interface for WWW::MLite on CTK::DBI based.
DEBUG
Set $WWW::MLite::Store::DBI::DEBUG_FORCE = 1 for enable debugging in STDERR where object $mlite undefined
Coming soon
METHODS
- ping
-
my $status = $mysql->ping();
Returns connection's life status
- reconnect
-
$mysql->reconnect unless $mysql->ping();
- err, errstr, state
-
my $err = $mysql->err; my $errstr = $mysql->errstr; my $state = $mysql->state;
Methods returns DBI values: err, errstr and state.
EXAMPLES
- Example 1
-
use WWW::MLite::Store::DBI; # eval 'sub CTK::DBI::_error {1}'; # For supressing CTK::DBI errors my $mysql => new WWW::MLite::Store::DBI ( -mlite => $mlite, -dsn => 'DBI:mysql:database=NAME;host=HOST', -user => 'USER', -pass => 'PASSWORD', -attr => { mysql_enable_utf8 => 1, RaiseError => 0, PrintError => 0, HandleError => sub { $m->log_error(shift || '') }, }, ) ... my @data = $mysql->table('select * from table');
- Example 2: with reconnection
-
use WWW::MLite::Store::DBI; my $mysql => new WWW::MLite::Store::DBI ( -mlite => $mlite, # OPTIONAL -dsn => 'DBI:mysql:database=NAME;host=HOST', -user => 'USER', -pass => 'PASSWORD', -attr => { mysql_enable_utf8 => 1, RaiseError => 0, PrintError => 0, HandleError => sub { $m->log_error(shift || '') }, }, ) ... $mysql->reconnect unless $mysql->ping; ... my @data = $mysql->table('select * from table');
- Example 3: Oracle
-
# Oracle connect my $oracle = new WWW::MLite::Store::DBI ( -mlite => $mlite, # OPTIONAL -driver => 'Oracle', -host => '192.168.1.1', -database => 'TEST', -user => 'login', -pass => 'password', -attr => { RaiseError => 0, PrintError => 0, }, ) ... my $value = mysql->field('select sysdate from dual');
- Simple example
-
use WWW::MLite::Store::DBI; $WWW::MLite::Store::DBI::DEBUG_FORCE = 1; my $dbi = new WWW::MLite::Store::DBI ( -driver => 'mysql', -name => 'mylocaldb', -user => 'user', -password => 'password' ); ... my @table = $dbi->table("select * from tablename where date = ?", "01.01.2000");
- Sponge example
-
use WWW::MLite::Store::DBI; $WWW::MLite::Store::DBI::DEBUG_FORCE = 1; my $o = new WWW::MLite::Store::DBI( -driver => 'Sponge', -attr => { RaiseError => 1 }, ); my $dbh = $o->connect(); my $sth = $dbh->prepare("select * from table", { rows => [ [qw/foo bar baz/], [qw/qux quux corge/], [qw/grault garply waldo/], ], NAME => [qw/h1 h2 h3/], }); $sth->execute(); my $result = $sth->fetchall_arrayref; $sth->finish; print Dumper($result);
HISTORY
See CHANGES
file
SEE ALSO
AUTHOR
Serz Minus (Lepenkov Sergey) http://www.serzik.com <minus@mail333.com>
COPYRIGHT
Copyright (C) 1998-2014 D&D Corporation. All Rights Reserved
LICENSE
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
See LICENSE
file