Hello everyone. I have been away from PERL for quite a while, a few years actually. But I was looking at an old script that I wrote that I want to resurrect from the dead, so to speak. The old script was basically to help me learn now I am using that way again but it will go back up on the web at some point. When I originally wrote it, I didn't need a database, I just had a small amount of data that I kept in txt files. But now, I am expecting a lot more data so I am trying to move it to a db. I have a db and table populated with info. So I am trying to write a script to read the db line by line using fetchrow_array. But for some reason the script keeps popping a 500 error and there is nothing in my log files.

So the script so far seems pretty straight forward but I cannot for the life of me find the error. And no errors show up in my error logs and no error is displayed. Anyone see anything? All feedback greatly appreciated since I am just getting back into perl.

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; ## mysql user database name $db ="dbname"; ## mysql database user name $user = "dbuser"; ## mysql database password $pass = "abc123"; ## user hostname $host="localhost"; my $dsn = "DBI:mysql:database=$db;host=$host"; my $dbh = DBI->connect($dsn, $user, $pass) or die("Error connecting to the database: $DBI::errstr\n"); my $sql = qq/select * from table/; my $sth = $dbh->prepare ($sql); while (@row = $sth->fetchrow_array) { my ($a, $b, $c, $d ) = @row; print ("--", @row), "\n\n"; } $dbh->disconnect (); exit (0);

In reply to read database 500 error by PaganJim

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.