MySQL::mycrud - nothing but the mysql methods for myself
Version 0.03
use MySQL::mycrud; # connect to the database my $db = MySQL::mycrud->new('database_name','host','port','user','password'); # get one 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}; } # 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;
my $db = MySQL::mycrud->new('database_name','host','port','user','password');
create the object and connect to the database.
my ($name,$age) = $db->get_row("select name,age from table where id=123");
get one row, the result returned is a list.
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.
$db->do_sql("insert into table(name,age) values(?,?)",['John Doe',30]);
run any sql for updates, including insert,replace,update,delete,drop etc.
$db->disconnect;
disconnect from the database. anyway if $db is gone out of the scope, the database will be disconnected automatically.
DBI DBD::mysql
Ken Peng <yhpeng@cpan.org>
If you have found bugs, please send email to <yhpeng@cpan.org>
You can find documentation for this module with the perldoc command.
perldoc MySQL::mycrud
Copyright 2012 Ken Peng, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MySQL::mycrud, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::mycrud
CPAN shell
perl -MCPAN -e shell install MySQL::mycrud
For more information on module installation, please visit the detailed CPAN module installation guide.