NAME
MySQL::Easy::PYH - nothing special but the Mysql operation methods for my project
VERSION
Version 0.01
SYNOPSIS
use MySQL::Easy::PYH;
# connect to the database
my $db = MySQL::Easy::PYH->new('database_name','host','port','user','password');
# get a single row
my ($name,$age) = $db->get_row("select name,age from table where id=123"); # or
my ($name,$age) = $db->get_row("select name,age from table where id=?",[123]);
# get many rows
my $rr = $db->get_rows("select * from table where id between 123 and 456"); # or
my $rr = $db->get_rows("select * from table where id between ? and ?",[123,456]);
for my $r (@$rr) { # each element is a hash ref
print "$r->{name} $r->{age}\n";
}
# do updates
$db->do_sql("insert into table(name,age) values(?,?)",['John Doe',30]);
$db->do_sql("update table set age=32 where id=123");
$db->do_sql("delete from table where id=123");
# disconnect it
$db->disconnect;
METHODS
new(db_name,host,port,user,passwd)
my $db = MySQL::Easy::PYH->new('database_name','host','port','user','password');
create the object and connect to the database.
get_row(sql)
my ($name,$age) = $db->get_row("select name,age from table where id=123");
get a single row, the result returned is a list.
get_rows(sql)
my $rr = $db->get_rows("select * from table where id between 123 and 456");
get rows, the result returned is an array reference, each element in the array is a hash reference.
do_sql(sql)
$db->do_sql("insert into table(name,age) values(?,?)",['John Doe',30]);
run any sql for updates, including insert,replace,update,delete,drop etc.
disconnect()
$db->disconnect;
disconnect from the database. anyway if $db is gone out of the scope, the database will be disconnected automatically.
SEE ALSO
DBI DBD::mysql
AUTHOR
Peng Yong Hua <pyh@mail.nsbeta.info>
BUGS/LIMITATIONS
If you have found bugs, please send email to <pyh@mail.nsbeta.info>
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MySQL::Easy::PYH
COPYRIGHT & LICENSE
Copyright 2011 Peng Yong Hua, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.