Well, see if you can get to "first base", connect to the DB and run the first query.

See some untested code below... Once you get connected and have a database handle, the sequence is : prepare query ->execute query -> retrieve results. There are several "flavors" of result retrieval. I show an easy way below.

I recommend the following book, what DB are you using?
Programming the Perl DBI, Database programming with Perl By Tim Bunce, Alligator Descartes.

use DBI; my $database = 'somedatabase'; #your system specific my $hostname = 'localhost'; ##your system specific my $port = 3306; #default mysql port my $user = 'someuser'; #your system specific my $password = 'somepassword'; #your system specific my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port" or die "DB data set name failed $!\n"; my $dbh = DBI->connect($dsn, $user, $password, {RaiseError => 1}) or die "DB connect failed $!\n"; my $query = $dbh->prepare("SELECT c2.id, c2.name as 'client' FROM client c2 WHERE level = 50 and status = 1"); $query->execute(); while (my ($id, $name) = $query->fetchrow_array) { print "$id \t $name\n"; } __END__ To make a parameter a variable, use a placeholder: my $query = $dbh->prepare("SELECT c2.id, c2.name as 'client' FROM client c2 WHERE level = ? and status = ?"); $query->execute(50,1);
Update: added placeholder comment in code above. Also just tested a very similar query on my local MySQL installation. See if you can get this first part working.

In reply to Re^3: Help with MySQL SELECT into multidimensional array by Marshall
in thread Help with MySQL SELECT into multidimensional array by btongeorge

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.