in reply to OK, OK, I'm taking the DBI plunge. Now what?
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
|
|---|