I am trying to run me script in the background. I connect to a mysql db using: my $db = DBI->connect($dsn, $user, $pw,{'PrintError' => 1, 'RaiseError' => 1}) or die "Unable to connect: $DBI::errstr\n"; When i run the script (either in the background or manually) I receive this error:
DBD::mysql::st fetchrow_array failed: fetch() without execute() at has +-download-0.1.pl line 82. DBD::mysql::st fetchrow_array failed: fetch() without execute() at has +-download-0.1.pl line 82.
Then the script fails and goes no further. The line that spawns the error:
#~ Update status to 2 $query = "select status, dataid from radar_data where data +type=$data_type and hasid ='$HAS_break[5]';"; $query_handle = $db->prepare($query); $query_handle->execute(); while(my @row = $query_handle->fetchrow_array()) {
is not the first execute. Prior to the error I prepare and execute another query that goes without error. Not sure what the problem is and am wondering if anyone has any ideas?

the entire scripts (with commented error location):

#!/usr/local/bin/perl -w use strict; use Mail::Box::Manager; use HTML::TreeBuilder; use Proc::Background; use DBI; use DBD::mysql; #~ use lib '/usr/local/lib/perl5/site_perl/5.10.0/'; my $dataid; my $query; my $query_handle; my $data_type; my $format; my $cmd; my $mailspool = "/var/spool/mail/thor"; my $tmpfldr = "/home/thor/tmp"; my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open(folder => $mailspool, access => 'rw'); my @HAS; #~ DBI variables my $host = "localhost"; my $database = "thor"; my $user = "thor"; my $pw = "*******"; my $port = 22; my $dsn = "DBI:mysql:database=$database;host=$host;port=$port"; my $db = DBI->connect($dsn, $user, $pw,{'PrintError' => 1, 'RaiseError +' => 1}) or die "Unable to connect: $DBI::errstr\n"; if (defined($folder)){ my $emails = $folder->messages; print "There are $emails in $mailspool\n\nSearching For HAS URLs.. +.\n"; foreach my $message ($folder->messages) { my $subject = $message->get('Subject'); if ($subject =~ /^HAS\sData\sRequest:\sHAS\d{9}\sCompleted/){ #~ print "$subject\n"; my $body = $message->body; my @body = split(/\n/,$body); foreach my $string (@body){ next if $string !~ /^http:/; #~ print "$string\n\n"; push(@HAS,$string); } } #~ Need Root access to delete $message->delete; } $folder->close; if (my $hasnum = @HAS == 0) { print "\nThere are No Messages in the folder: $mailspool\n"; exit; } print "HAS URLs Stored: @HAS\n"; foreach my $HAS (@HAS){ my @hrefs; #~ Get the HAS number my @HAS_break = split(/\//,$HAS); #~ Search Database for HAS number #~ Retreive Data Type $query = "select datatype from radar_data where hasid ='$HAS_b +reak[5]' limit 1;"; $query_handle = $db->prepare($query); $query_handle->execute(); $query_handle->bind_columns(\$data_type); $query_handle->fetch(); #~ $data_type = to_int($data_type); #~ print "$data_type\n"; #~ Update status to 2 $query = "select status, dataid from radar_data where datatype +=$data_type and hasid ='$HAS_break[5]';"; $query_handle = $db->prepare($query); $query_handle->execute(); while(my @row = $query_handle->fetchrow_array()) { #ERROR HERE #~ Update only available data to 'Email Received' status if ($row[0] eq '1') { $query = "update radar_data set status=2 where dataid= +$row[1] and datatype=$data_type and hasid ='$HAS_break[5]';"; $query_handle = $db->prepare($query); $query_handle->execute(); } } print "Data type for $HAS: Level $data_type\n"; $format = "/thordata1/nexrad/NIDS" if $data_type eq '3'; $format = "/thordata1/Level2" if $data_type eq '2'; #~ print "$data_type\n"; print "Using Directory: $format\n"; #~ Create HAS directory $cmd = "mkdir $format/$HAS_break[5]"; print "$cmd\n"; system($cmd); #~ Download HAS files $cmd = "wget $HAS -O $tmpfldr/index.html"; print "$cmd\n"; system($cmd); #~ Parse the html from NCDC my $tree = HTML::TreeBuilder->new_from_file("$tmpfldr/index.ht +ml") or die "Cant build tree: $!\n"; my @anchors = $tree->look_down(_tag => q{a}); #~ print "@anchors\n"; foreach my $anchor (@anchors) { if ($anchor->as_text =~ /\.tar/) { push @hrefs, $anchor->attr(q{href}); print "File Available: ",$anchor->as_text,"\n"; } } #~ Download Files foreach my $hrefs (@hrefs) { $cmd = "wget $HAS$hrefs -O $format/$HAS_break[5]/$hrefs"; print "$cmd\n"; system($cmd); } #~ Update status to 3 $query = "select status, dataid from radar_data where datatype +=$data_type and hasid ='$HAS_break[5]';"; $query_handle = $db->prepare($query); $query_handle->execute(); while(my @row = $query_handle->fetchrow_array()) { #~ Update only available data to 'Downloaded' status if ($row[0] eq '2') { $query = "update radar_data set status=3 where dataid= +$row[1] and datatype=$data_type and hasid ='$HAS_break[5]';"; $query_handle = $db->prepare($query); $query_handle->execute(); } } #~ Delete temp file/html $cmd = "rm -rf /research/SSRG/ThOR/tmp/index.html"; print "$cmd\n"; system($cmd); #~ Start a background process and pass the data type to it to +mine the downloaded data my $command = "nohup /usr/local/bin/perl /home/thor/Programs/t +esting/has-miner-0.1.pl $HAS_break[5] $format $data_type"; my $proc = Proc::Background->new($command); print "Miner Started: ",$proc->pid,"\n" if defined $proc; + } }else{ print "\nThere are No Messages in the folder: $mailspool\n"; } $db->disconnect(); exit;

In reply to DBD::mysql fetchrow_array failed by deadpickle

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.