Are you getting an error with this code? If so we can help you more if you post it.

Just looking through it: you seem to be headed in the right direction. The only thing that i see is that you need single quotes around your "Yes" in your query so it reads:

SELECT * FROM info WHERE field_3='Yes'

Actually an even better way to do it is to use place holders, like this:

SELECT * FROM info WHERE field_3=?

Then in your execute statement:

$sth->execute('Yes') or die ....

The use of place holders is really helpful because it escapes characters that can potentionally cause your query to fail. Not as important with this example since you have a hard-coded string but it is very important when you start using variables.

UPDATE: Helps to read the last part of the question :)

To get your data out you need to fetch it. I typically fetch data into array of hash references like this:

#execute statement here my @data = (); # define an array while(my $row = $sth->fetchrow_hashref()) { push(@data,$row); } # finish and disconnect

Then its a pretty simple matter to access all your data. Each hash key is the name of the field. So if you wanted the first field of the first entry in your data base you just dereference the hash like so:

my $field_1 = $data[0]->{'field_1'};

Of course if you want to process the data all at once you don't really need an array at all:

Hope that helps
Chris


In reply to Re: OK, OK, I'm taking the DBI plunge. Now what? by cfreak
in thread OK, OK, I'm taking the DBI plunge. Now what? by peppiv

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.