First of all, you need to load DBI.pm into your script for any of the database functions you are using to work. Then you have to connect to the database.

I've got 2 words for you:
perldoc DBI :-)

You really need to read the docs for that(that command will get them for you), and perhaps even give yourself a rundown on packages and modules. Rework your code after that then come back and ask.

For now a little demonstration of DBI.pm:

#!/usr/bin/perl use DBI; use strict; # connect to the database, using mysql in example my $dbh = DBI->connect("DBI:mysql:dbname:hostname", "user", "pass") or + die "Couldn't Connect: $DBI::errstr"; # prepare statement handle $sth = $dbh->prepare("SELECT * FROM table WHERE field = ?); # ? is a placeholder that can be filled when execute is called $sth->execute($val_of_field) or die "Error: $DBI::errstr"; # $DBI::errstr stores the error string returned by the DB while (@vals = $sth->fetchrow->array()) { # do stuff # do more stuff } $sth->finish(); #close statement handle $dbh->disconnect(); #disconnect
You also need to make sure that DBI.pm is installed on your system. Type:
perl -e 'use DBI;' at your command line. If its installed nothing will happen, if not you'll get an error like:
Can't locate Blah.pm in @INC (@INC contains: /home/harvester/lib/perl5 +/i386-linux /home/harvester/lib/perl5 /usr/lib/perl5/5.00503/i386-lin +ux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux / +usr/lib/perl5/site_perl/5.005 .) at -e line 1. BEGIN failed--compilation aborted at -e line 1.
Really you should just start out by reading some docs and getting a better understanding of how to use DBI.pm

Amel - f.k.a. - kel


In reply to Re: Display row with no value in column by dsb
in thread Display row with no value in column by nlafferty

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.