[perl]: perl to database ( MariaDB )
一、说明
1、 暂无
二、源码
1 #!/usr/bin/perl -w 2 3 4 # file_name: db.pl 5 6 7 use strict; 8 use DBI; 9 10 sub database 11 { 12 my $host = "192.168.11.30"; # your_database_server_ip 13 my $driver = "MariaDB"; 14 my $db = "dbtest"; # your_database 15 my $dsn = "DBI:$driver:database=$db:$host"; 16 my $user = "root"; # your_database_user 17 my $passwd = "ab123456"; # your_database_password 18 19 20 # connect to db 21 my $dbh = DBI->connect($dsn, $user, $passwd ) or die $DBI::errstr; 22 my $sth = $dbh->prepare("SELECT * FROM test"); 23 $sth->execute(); # sql 24 25 26 # get data; then output 27 while ( my @row = $sth->fetchrow_array() ) 28 { 29 print join("\t", @row)."\n"; 30 } 31 32 33 $sth->finish(); 34 $dbh->disconnect(); 35 } 36 37 38 # run part 39 database();
三、运行结果
1 [wit@fedora perl]$ ./db.pl 2 1 wit 18012345678 gansu 3 2 god 18112345678 liaoing 4 3 six 18212345678 heilongjiang 5 4 big 18312345678 menggu 6 5 one 18412345678 henan 7 6 next 18512345678 hebei 8 7 break 18612345678 guangxi 9 8 bad 18712345678 xizang 10 9 work 18812345678 shandong 11 [wit@fedora perl]$ 12 [wit@fedora perl]$
四、参考资料
1、 Perl 数据库连接 -- https://www.runoob.com/perl/perl-database-access.html
标签:DBI,database,db,perl,MariaDB,my From: https://www.cnblogs.com/lnlidawei/p/17991305