biofeng918 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use DBI; #connecting the database test1 my $dbh=DBI->connect('DBI:mysql:test1') or die "cannot connect the dat +abase:".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;#//
while run it ,it says that no database driver specified and DBI_DSN env var not set at line4.I just need someone to tell me why.Thank you!
while I run this overrighted version,it says access denied for user 'ODBC'@'localhost' <using paassword :NO> at line 4.,I till don't know why ,I hope someone can help me,thank you!
whILE i run these code ,it still doesn,t work,it says thatit needs explicit package name for inputdata at 13,14,15,16line and it needs explicit package name for inputname at 25,27,28,29line
I need someone to tell me why,thanks!!!20050109 Janitored by Corion: Added formatting
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how perl can connect with mysql
by cchampion (Curate) on Jan 09, 2005 at 11:37 UTC | |
by biofeng918 (Acolyte) on Jan 09, 2005 at 13:05 UTC | |
by cchampion (Curate) on Jan 09, 2005 at 14:11 UTC | |
by biofeng918 (Acolyte) on Jan 09, 2005 at 15:07 UTC | |
Re: how perl can connect with mysql
by trammell (Priest) on Jan 09, 2005 at 15:47 UTC |