NAME
Ananke::SqlLink - Front-end module to MySQL
DESCRIPTION
MySQL easy access
SYNOPSIS
#!/usr/bin/perl]
use strict;
use Ananke::SqlLink;
my(@r,$c,$q,$i);
# Open DB
$c = new Ananke::SqlLink({
'type' => 'mysql',
'db' => 'test',
'host' => 'localhost',
'username' => 'root',
'passwd' => '',
});
# Query Insert
$q = "INSERT INTO test (id,name) VALUES (null,'user')";
$c->do($q); undef $q;
# Query Select
$q = "SELECT id,name FROM test";
# Result 1
print "- Scalar\n";
@r = $c->return($q,'scalar');
foreach $i (@r) {
print "ID: ".$i->{id}." - Name: ".$i->{name}."\n";
}
# Result 2
print "- Array\n";
@r = $c->return($q,'array');
foreach $i (@r) {
print "ID: ".${$i}[0]." - Name: ".${$i}[1]."\n";
}
# Close DB
$c->disconnect;
METHODS
new({type,db,host,username,passwd})
Create a new SqlLink object.
my $c = new Ananke::SqlLink({
'type' => 'mysql',
'db' => 'test',
'host' => 'localhost',
'username' => 'root',
'passwd' => '',
});
$c->return(type,query)
only for select
scalar type
@r = $c->return($q,'scalar');
foreach $i (@r) {
print "ID: ".$i->{id}." - Name: ".$i->{name}."\n";
}
array type
@r = $c->return($q,'array');
foreach $i (@r) {
print "ID: ".${$i}[0]." - Name: ".${$i}[1]."\n";
}
$c->do(query)
to insert,update,replace,etc...
$q = "INSERT INTO test (id,name) VALUES (null,'user')";
$c->do($q); undef $q;
$c->disconnect()
disconnect
$c->disconnect();
$c->insertid()
return last insert id
$c->quote(string)
AddSlashes
$q = "INSERT INTO test (id,name) VALUES (null,'".$c->quote($user)."')";
AUTHOR
Udlei D. R. Nattis
nattis@anankeit.com.br
http://www.nobol.com.br
http://www.anankeit.com.br