in reply to eval() issues.

How do you know that you successfully opened PNG?
Check to see if you opened the file before you try and write to it.
The typical thing to do is
open FH, ">somefile" || die "Could not open somefile : $!";
On another note. Make sure you check for errors on all your DBI calls (execute, prepare, connect, fetch...). It is better if you open your DBI database handle to throw errors so they can be caught by an exception handler (eval). You do this in the 4th arg of DBI's connect. Like ...
$dbh = DBI->connect('dbi:DBDnamehere:connectstringhere','userid', ' +password', {RaiseError => 1});