SimpleDBI some function base DBI
support mysql
use SimpleDBI::mysql; use Encode; use utf8; my $mysql = SimpleDBI::mysql->new( db => 'testdb', host => '127.0.0.1', usr => 'someusr', passwd => 'somepwd', #enable_utf8 => 1, );
my $data = $mysql->query_db('select * from sometable limit 2', result_type => 'arrayref', # arrayref, hashref, file #attr => ..., # sql query attr, #bind_values => ..., # sql query bind values, #hash_key => [ qw/id prov/ ], #hashref key #file => 'sometable.txt', # file name #sep => ',', ); print encode( 'utf8' , $_ ), "\n" for @{ $data->[0] };
my $test_file = 'xxx.txt'; my $test_data = [ [qw/1 测试/], [qw/2 无聊/], ]; $mysql->load_table( $test_data, # or $test_file, table => 'testtable', fields => [qw/id name/], #db => 'otherdb', #charset => 'utf8', #replace => 0, #sep => ',', );
To install SimpleDBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SimpleDBI
CPAN shell
perl -MCPAN -e shell install SimpleDBI
For more information on module installation, please visit the detailed CPAN module installation guide.