php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45999 MySQL/PDF clash
Submitted: 2008-09-05 00:00 UTC Modified: 2008-09-13 01:00 UTC
From: markem at airmail dot net Assigned:
Status: No Feedback Package: PDF related
PHP Version: 5.2.6 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: markem at airmail dot net
New email:
PHP Version: OS:

 

 [2008-09-05 00:00 UTC] markem at airmail dot net
Description:
------------
I'm unsure if I have the actual cause - but....

I'm working on a large report.  They would like for it to be in PDF.  So I'm using PDFLIB.  If all of the code is together - the PDF is generated with no problems.  Unfortunately, between the pdf_new() and then other pdf commands there is an SQL call to MySQL.  When that is finished the error I get back is:

PHP Fatal error:  Uncaught exception 'PDFlibException' with message 'pdf_open_file(): 6 is not a valid pdf object resource'

The #6 is the resource ID (if I put in echo statements to print out $myPDF it prints "6") of the PDF document.  So it is like PHP is closing out the PDF document (or maybe just dumping the resource info).

Reproduce code:
---------------
        $myPDF = pdf_new();
        pdf_open_file( $myPDF, "" );                        #   We use a "" if the output is coming
        pdf_begin_page( $myPDF, 11 * 72, 8.5 * 72 );        #   Paper resolution is 72dpi.  Always use inches.
        pdf_translate( $myPDF, 0, 8.5 * 72 );               #   Translate where the origin is to the top-left.
        pdf_scale( $myPDF, 1, -1 );                     #   Rescale everything.
        pdf_set_value( $myPDF, "horizscaling", -100 );  #   Set the horizontal scaling to -100%.

        $font = pdf_load_font( $myPDF, "Helvetica","iso8859-1", "" );
        if( $font ){ pdf_setfont( $myPDF, $font, -18.0 ); }

        $theString = "Palliative and Supportive Care Inpatient | Consult List";

        pdf_show_boxed( $myPDF, $theString, 20, 50, 500, 20, "center", "" );
        pdf_setcolor( $myPDF, "fill", "rgb", 0.9, 0.9, 0.9, 0.0 );
        pdf_rect( $myPDF, 20, 50, 300, 20 );
        pdf_fill_stroke( $myPDF );

        pdf_end_page( $myPDF );
        pdf_set_parameter( $myPDF, "openaction", "fitpage" );
        pdf_close( $myPDF );

        $buf = pdf_get_buffer( $myPDF );
        $len = strlen( $buf );
        header( "Content-Type:application/pdf" );
        header( "Content-Length:$len" );
        header( "Content-Disposition:inline; filename=DailyRpt.pdf" );
        echo $buf;
        pdf_delete( $myPDF );

Expected result:
----------------
The above code works so long as it is all together.  I get a single PDF page which reads "Palliative and Supportive Care Inpatient | Consult List".

Actual result:
--------------
However, if an SQL command is sent to the database between the "pdf_new()" and the "pdf_open_file()" commands, no PDF document is generated and Apache gives the above error.

Example SQL command:
    $sql = <<<END_OF_SQL
SELECT  distinct B.VISIT_TYPE, B.Patient_class, A.LAST_NAME, A.FIRST_NAME,
    A.MIDDLE_NAME, A.MRN, B.PC_MD, B.PC_FELLOW, B.PC_NP, B.ROOM,
    to_char( B.PC_ADMISSION_DATE, 'MM/DD/YYYY') as  VISITS_DATE, B.CONSULTING_MD,
    A.DOB, B.VISITID, B.PRK, B.PC_NP, N.LAST_NAME AS PC_FELLOW_LN,
    N.FIRST_NAME AS PC_FELLOW_FN, O.LAST_NAME AS PC_NP_LN, O.FIRST_NAME AS PC_NP_FN,
    B.VISITID, B.PRK, to_char( A.DOB, 'MM/DD/YYYY') AS ADOB,
    P.Last_Name as CONSULTING_MD_LAST_NAME, P.HOSPITAL_SERVICE_CD, B.VISIT_COMMENT
        FROM  Patients_VW A, Visits B, PALLIATIVE_PATIENTS L, EMPLOYEES_VW N, EMPLOYEES_VW O, PHYSICIANS_VW P
        WHERE  B.Care_Discharged_Date IS NULL
            AND  ( B.Patient_class = 1  OR  B.Patient_class = 5 )
            AND  B.PC_FELLOW = N.EMPLID( + )
            AND  B.PC_NP = O.EMPLID( + )
            AND  B.CONSULTING_MD = P.PHYSICIAN_ID( + )
            AND  B.PRK = A.PRK
            AND  B.PRK = L.PRK
        ORDER BY B.ROOM
END_OF_SQL;


NOTES:  This program already works and can produce an HTML report.  There are four sections to the report, thus, I have to produce four different pages in the PDF document before I can actually close it.  This was the first of the pages.  It took me four hours to figure out just what was going on.  (Commented out each command separately, then in groups, then started moving the commands around.  Finally got to the point of having all of the PDF commands together rather than some at the start of the program, and some in the middle.)

Ideas?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-06 00:48 UTC] jani@php.net
Please provide the shortest possible self-contained and complete (!) 
reproducing script (max 20 lines!). And one that can be run with CLI.
 [2008-09-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC