Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am pulling information from a MySQL database one row at a time, then while looping through the table i am running a script that creates a pdf, on each row based on there info. I loop through the first row and it works just fine, it gets to the second record and bails halfway through. this is the error
Uncaught exception from user code: Can't call method "new_obj" on unblessed reference at C:/Perl/site +/lib/PDF/API2/Resource.pm line 66. at C:/Perl/site/lib/PDF/API2/Resource.pm line 66 PDF::API2::Resource::new('PDF::API2::Resource::XObject::Image::PNG +', 'undef', 'PxCBQ') called at C:/Perl/site/lib/PDF/API2/Resource/XOb +ject.pm line 64 PDF::API2::Resource::XObject::new('PDF::API2::Resource::XObject::I +mage::PNG', 'undef', 'PxCBQ') called at C:/Perl/site/lib/PDF/API2/Res +ource/XObject/Image.pm line 65 PDF::API2::Resource::XObject::Image::new('PDF::API2::Resource::XOb +ject::Image::PNG', 'undef', 'PxCBQ') called at C:/Perl/site/lib/PDF/A +PI2/Resource/XObject/Image/PNG.pm line 62 PDF::API2::Resource::XObject::Image::PNG::new('PDF::API2::Resource +::XObject::Image::PNG', 'undef', 'assets/VMwareTCOChart35.png') calle +d at C:/Perl/site/lib/PDF/API2/Resource/XObject/Image/PNG.pm line 298 PDF::API2::Resource::XObject::Image::PNG::new_api('PDF::API2::Reso +urce::XObject::Image::PNG', 'PDF::API2=HASH(0x2eb962c)', 'assets/VMwa +reTCOChart35.png') called at C:/Perl/site/lib/PDF/API2.pm line 1816 PDF::API2::image_png('PDF::API2=HASH(0x2eb962c)', 'assets/VMwareTC +OChart35.png', '-lossless', 1) called at C:\WEB_ROOT\dbcall\VMwareTCO +DBReport.pl line 1032 main::setImage('assets/VMwareTCOChart35.png', 311.811023622047, 46 +7.716535433071, 270, 225) called at C:\WEB_ROOT\dbcall\VMwareTCODBRep +ort.pl line 358
I am not sure why its causing this error, any help would be great, here is the loop I am using minus the pdf code its too long.
#!/usr/bin/perl -w BEGIN { use CGI::Carp qw(carpout); open(\*MYLOG, '>>', "VMwith-db.log") or die("Unable to open perl.log: $!\n"); carpout(MYLOG); } use PDF::API2; use PDF::Table; use perlchartdir; use DBI; use MIME::Lite; use strict; use warnings; use diagnostics; use CGI qw(:standard); use constant mm => 25.4/72; use constant in => 1/72; use constant pt => 1; my %valueHash; my %User_Preferences; my $q = new CGI; print $q->header( "text/plain" ); open( CONFIG, 'variables.conf' ); while (<CONFIG>) { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); $User_Preferences{$var} = $value; } close (CONFIG); my $dbhost = $User_Preferences{"localhost"}; my $dsn = "dbi:mysql:$User_Preferences{\"dbName\"}:$dbhost"; my $db_user_name = $User_Preferences{"db_user_name"}; my $db_password = $User_Preferences{"db_password"}; my $dbh = DBI->connect($dsn, $db_user_name, $db_password); my $selectState = qq{SELECT uid, fparams FROM vmware WHERE flag = 10}; my $sth = $dbh->prepare($selectState); $sth->execute or die "Can't execute SQL statement: $DBI::errstr\n"; ## search through the database - so we can run the pdf for every row while ((my $key, my $row) = $sth->fetchrow_array()) { my $workingFlag = qq{UPDATE vmware SET flag = 20 WHERE uid = $ +key}; $dbh->do($workingFlag) or die "Can't Update DataBase: $DBI::er +rstr\n"; my $fparams = join('', $row); %valueHash = map split(/=/, $_, 2), split /\|\|/, $fparams; #while( my($key2, $value2) = each(%valueHash)){ # print " KEY: $key2..... VALUE: $value2 \n "; #} #do PDF Stuff HERE .... }#WHILE LOOP THROUGH THE db warn"Data fetching terminated early by error: $DBI::errstr\n" if $DBI: +:err;

In reply to Error when trying to loop through DB and run a script by ikkon

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others scrutinizing the Monastery: (3)
    As of 2024-07-15 19:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.