标签:style blog http io ar color os sp for
先写在这里吧,之后再改进~~
package mysql_conn; use DBI; use strict; sub new{ my $class = shift(); print ("CLASS=$class\n"); my $self={}; $self->{"location"} = shift(); $self->{"db_name"} = shift(); $self->{"db_user"} = shift(); $self->{"db_pass"} = shift(); bless $self,$class; return $self; } sub get_table_flag_1_3{ my ($self,$TABLE)=@_; my $port = "3306"; #这是mysql的缺省 my $location=$self->{"location"}; my $db_name=$self->{"db_name"}; my $db_user = $self->{"db_user"}; my $db_pass = $self->{"db_pass"}; my $database = "DBI:mysql:$dbname:$location:$port"; my $dbh = DBI->connect($database,$db_user,$db_pass) or die "Cann‘t connect the Database".DBI->errstr; my $sql = "SELECT file,owner FROM TABLE where flag=1 or flag=3"; my $sth = $dbh->prepare($sql); my $result=$sth->execute() or die "db operation Error:$dbh->errstr"; #执行 $sth->finish(); $dbh->disconnect;#断开数据库连接 return $result; }
fetchrow_array ()抽取方法的返回是一个包含查询结果的数组。还有其它方法:
fetchrow_arrayref ()返回一个数组引用。
fetchrow_hashref ()返回散列引用。
use strict ;标签:style blog http io ar color os sp for
原文地址:http://my.oschina.net/u/347414/blog/353937