#!/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
In reply to how perl can connect with mysql by biofeng918
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |