Hi everyone, I'm very new to Perl, and I was having a bit of an issue with MySQL and Perl. What I want to do is take the output result and assign it to a Perl variable. Here's what I have so far:

use DBI; my $dsn = 'driver={SQL Server}; Server=SERVERNAMEHERE; database=DBNAMEHERE; uid=UIDHERE; pwd=PWHERE'; my $dbh = DBI->connect("dbi:OOOO:$dsn",{AutoCommit => 1}) or die "$DB +I::errstr\n"; my $sql = "select field1, field2 from location where restriction = 'RE +STRICTION NAME'"; my $sth = $dbh->prepare( $sql ); $sth->execute(); $sth->finish(); $dbh->disconnect();

As you can see, I only show the actual SQL statements, I've looked at countless forum posts to help solve my problem but I don't think they answer my question accurately. For a little more information, the mySQL statement works fine and returns about 100+ results. I want to assign those results to Perl variables, and then pass those variables into another subroutine which utilizes SOAP::Lite If you'd like to take a look, here's the Perl code which I attempted to write thus far, but I only get one result which contains two fields, and not the additional hundred. Would I need to use an array as well?

use DBI; my $dsn = 'driver={SQL Server}; Server=SERVERNAMEHERE; database=DBNAMEHERE; uid=UIDHERE; pwd=PWHERE'; # my %info = ( # field1 => "field1", # field2 => "field2" # ); my $dbh = DBI->connect("dbi:OOOO:$dsn",{AutoCommit => 1}) or die "$DB +I::errstr\n"; #my $ref = $dbh->selectall_arrayref("select field1, field2 from locati +on where restriction = 'RESTRICTION NAME'"); my $sql = "select field1, field2 from location where restriction = 'RE +STRICTION NAME'"; my $sth = $dbh->prepare( $sql ); $sth->execute(); my @record = $sth->fetchrow_array; #my $href = $dbh->selectall_hashref("select field1, field2 from locati +on where restriction = 'RESTRICTION NAME'"); #print "$_\n" for (keys %$href); # foreach (@record){ # print $_; # } print join(", ", @record); $sth->finish(); $dbh->disconnect();

In reply to MySQL results inserted into Perl variable by shake7

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.