#!/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&#129;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&#129;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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.