Ananke::SqlLink - Front-end module to MySQL
MySQL easy access
#!/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;
Create a new SqlLink object. my $c = new Ananke::SqlLink({ 'type' => 'mysql', 'db' => 'test', 'host' => 'localhost', 'username' => 'root', 'passwd' => '', });
only for select
@r = $c->return($q,'scalar'); foreach $i (@r) { print "ID: ".$i->{id}." - Name: ".$i->{name}."\n"; }
@r = $c->return($q,'array'); foreach $i (@r) { print "ID: ".${$i}[0]." - Name: ".${$i}[1]."\n"; }
to insert,update,replace,etc... $q = "INSERT INTO test (id,name) VALUES (null,'user')"; $c->do($q); undef $q;
disconnect $c->disconnect();
return last insert id
AddSlashes $q = "INSERT INTO test (id,name) VALUES (null,'".$c->quote($user)."')";
Udlei D. R. Nattis nattis@anankeit.com.br http://www.nobol.com.br http://www.anankeit.com.br
To install Ananke::SqlLink, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ananke::SqlLink
CPAN shell
perl -MCPAN -e shell install Ananke::SqlLink
For more information on module installation, please visit the detailed CPAN module installation guide.