#!/usr/bin/perl -w use strict; use DBI; #connecting the database test1 my $dbh=DBI->connect('DBI:mysql:test1') or die "cannot connect the database:".DBI->errstr; print"insert records:"; my$sth=$dbh->prepare(q{ insert into mytable(name, sex, birth,birthaddr)values(?,?,?,?) }); print"enter records:"; while($inputdata=<>){ chop $inputdata; last unless($inputdata); my($name,$sex,$birth,$birthadrr)=split(/,/,$inputdata); $sth->excute($name,$sex,$birth,$birthadrr) } # $dbh->commitG print"print the sex and the birth according to the name entered"; my $sth=$dbh->prepare('select * from mytable where name=?') or die $dbh->errstr; print"please enter the nameF"; while($inputname=<>){ my @data; chomp $inputname; last unless($inputname); $sth->execute($inputname) or die "error".$sth->erstr; while(@data=$sth->fetchrow_array()){ print"sex:$data[2]t birth:$data[3]n"; } } #disconnecting $dbh->disconnect;#//