Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #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/ line 66. at C:/Perl/site/lib/PDF/API2/ line 66 PDF::API2::Resource::new('PDF::API2::Resource::XObject::Image::PNG +', 'undef', 'PxCBQ') called at C:/Perl/site/lib/PDF/API2/Resource/XOb 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/ 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/ 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/ 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/ line 1816 PDF::API2::image_png('PDF::API2=HASH(0x2eb962c)', 'assets/VMwareTC +OChart35.png', '-lossless', 1) called at C:\WEB_ROOT\dbcall\VMwareTCO line 1032 main::setImage('assets/VMwareTCOChart35.png', 311.811023622047, 46 +7.716535433071, 270, 225) called at C:\WEB_ROOT\dbcall\VMwareTCODBRep 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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2023-10-03 01:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found