Why ? Why everything is against me ? :)
Well let's tell you. Here is some small code that doesn't work. Very easy, just connect to database MySQL, select, (print), and disconnect. But... It's my first use of DBI and DBD::Mysql.

#! perl -w use strict; use DBI; use DBD::mysql; # Connect DataBase my $dbh = DBI->connect('DBI:mysql:CCM', 'root', ''); ###### THIS DOESN'T WORK :( ##### # Prepare the SQL query for execution my $sth = $dbh->prepare(<<End_SQL) or die "Couldn't prepare statement: + $DBI::errstr; stopped"; SELECT f1, f2, f3, f4, f5, f6 FROM forum WHERE f1 = 10 End_SQL ###### THIS WORK FINE ##### # my $sth = $dbh->prepare(<<End_SQL) or die "Error: i$DBI::errstr; sto +pped"; # INSERT INTO forum values(10, "foo", "bar", "foobar", "barfoo", "barb +ar") # End_SQL $sth->execute() or die "Error: $DBI::errstr; stopped"; # Fetch each row and print it my ($f1, $f2, $f3, $f4, $f5, $f6) = $sth->fetchrow_array(); print STDOUT "$f1 $f2 $f3 $f4 $f5 $f6\n"; my $title = $sth->fetchrow_array(); print $title; # Disconnect Database $dbh->disconnect();

In fact, this may work but give me this error message:

DBI::db=HASH(0x1d2bae0)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at C:\WINDOWS\Profiles\bob\Desktop\ccm_forum.pl line 32.

That mean on the last line during DISCONNECT(). I don't really understand this message...
So I am searching for enlightement from The God PERL.
Thanks.

BobiOne KenoBi ;)


In reply to Error with SELECT and MySQL by bobione

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.