NAME
PowerTools::Data - Additional Perl tool for Apache::ASP - MySQL database connection
SYNOPSIS
use PowerTools::Data;
# Create new object using params
my $db = PowerTools::Data->new(
# Username
username => 'mysql', # default 'root'
# Password
password => 'grendel1981', # default ''
# Database name
database => 'test', # default 'test'
# Hostname
hostname => 'localhost, # default 'localhost';
# Port
port => 3306, # default 3306;
# Protocol compression (0/1)
compression => 1, # default 1;
# DBI's RaiseError (0/1)
errors => 1, # default 1;
# DBI's AutoCommit (0/1)
commit => 1 # default 1;
);
# Create new object using .INI file
my $db = PowerTools::Data->new(
# Path to .INI file
ini => 'test.ini' # default ''
);
# Note: You can change .ini extension to other
# Remember to secure choosen extensions name in Your Apache config
# Connects to database
my $conn = $db->connect;
# Connection status (0 - FAIL/1 - OK)
my $s = $db->status;
print "STATUS $s\n";
# MySQL Server info
my $s = $db->{_SERVER_INFO};
print "SERVER $s\n";
# MySQL Server host info
my $s = $db->{_HOST_INFO};
print "HOST $s\n";
# Executes SQL statement
my $ex = $db->execute("INSERT INTO test (test_val1,test_val2) VALUES ('a','b')");
# Items count
my $cn = $db->count;
print "COUNT INSERT $cn\n";
# Last inserted item
my $lt = $db->last;
print "LAST ITEM $lt\n";
# Query execute time
my $tk = $db->took;
print "TOOK $tk\n";
# Parse query result
while(!$db->eof) {
my $str = "-> ".$db->field('test_id').", ".$db->field('test_val1').", ".$db->field('test_val2').", ".$db->field('test_val3');
print "$str\n";
$db->movenext;
}
# Additional tools
# Get (in MySQL format) current: date ('GET_MYSQL_DATE'), datetime ('GET_MYSQL_DATETIME'), time ('GET_MYSQL_TIME'), timestamp ('GET_MYSQL_TIMESTAMP')
my $cur = $db->tools('GET_MYSQL_TIMESTAMP');
print "$cur\n";
# Returns time object from MySQL's: date ('RETURN_TIME_DATE'), datetime ('RETURN_TIME_DATETIME'), timestamp ('RETURN_TIME_TIMESTAMP')
my $cur = $db->tools('RETURN_TIME_TIMESTAMP',$cur);
print "$cur\n";
AUTHOR
Piotr Ginalski, <office@gbshouse.com>
COPYRIGHT AND LICENSE
Copyright (C) 2007 by A. U. Thor
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.