Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Retrieving a PDF file from a MSSQL data base with php

Posted on 2003-03-01
Medium Priority
Last Modified: 2013-12-13
Here my code:

 //connect data base and select the table....
 $SQuery = "select len,pdfdata from PDFTable where nid = 34"
 // the entry exist
 // fetch the only row
 $row = mssql_fecth_row($SQuery);
 // ok!!
 header("Content-type: application/pdf");
 header("Content-lenght: ".$row[0]);
 print $row[1];

 The script launch the PDF program, but it remains in the list of process getting the 100% of the CPU.
 I think that the data are not completed, due to when i delete the headers lines, the binary code appears into the browser, but is not complete!!!, i think only it show 4096 bytes of the file instead of the 65470 of its real lenght.....

I did the same test using ASP .NET and the code, similar from the above works fine, but i need make it in PHP.
 Any limitations?, any wrong in the php code? or maybe this language script is not ready to work with MSSQL Server?.

Thank´s in advantage.

Question by:elnexus
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8074010
It's a round about way of fixing it, but others have solved this problem using the DUMPFILE flag in their query.

For your query it would look like:

$SQuery="SELECT len,pdfdata from PDFTable WHERE nid=34 DUMPFILE \"/tmp/temp.pdf\""

Then read in the file and display it.

By the way, if the PDF is 65470 bytes, I assume you are using MEDIUM BLOBs or larger?


Accepted Solution

klewlis earned 800 total points
ID: 8155047
you have Content-lenght instead of Content-length


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question