NAME

MySQL::mycrud - nothing but the mysql methods for myself

VERSION

Version 0.01

SYNOPSIS

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;

METHODS

new(db_name,host,port,user,passwd)

my $db = MySQL::mycrud->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 one 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

Ken Peng <yhpeng@cpan.org>

BUGS/LIMITATIONS

If you have found bugs, please send email to <yhpeng@cpan.org>

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc MySQL::mycrud

COPYRIGHT & LICENSE

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.