Solved

pulling a BLOB from SQL2k works with Java but corrupts with PHP

Posted on 2009-04-08
3
177 Views
Last Modified: 2012-05-06
Hi
I'm pulling back some data with Java and all works fine yet I want to move from Java to PHP and have mimicked the requirements with all working well except the PDF files that are created simply give the message "There was an error opening this document. The file is damaged and could not be repaired"

Any idea's what I'm doing wrong? as I say if I use the same code (but ported to Java) it works fine?

I've attachec the code below and a copy of the created pdf (just amended extension to .txt)

Thanks
Neil
<?php 

header("Content-Type: application/pdf"); 	
 

$docPath = "" . $_GET['from'];	

$server="####";

$username="####";

$password="####";

$db = "####";

$sqlconnect=mssql_connect($server, $username, $password);

$sqldb=mssql_select_db($db,$sqlconnect);	
 

$sql="SELECT c_content"

. "\n FROM ####.####.t_cadsdoc"

. "\n WHERE c_reference = '" . mysql_escape_string( $docPath ) . "'"

;

$results = mssql_query($sql);

$row=mssql_fetch_array($results);	

mssql_close($sqlconnect);

		

echo $row['c_content'];	

?>

Open in new window

buildPDF.txt
0
Comment
Question by:NeilT
  • 2
3 Comments
 
LVL 3

Author Comment

by:NeilT
ID: 24095169
I've jus tfound out the PHP created file when opening in textpad is about 50 times smaller than the correct PDF file opened in textpad
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 24095274
AFAIk you can't read blobs via the mssql_fetch_array-funvtion.
Check out http://odbtp.sourceforge.net/ as a possible solution for this issue, or try stored procured with mssql like described
http://www.php.net/manual/en/function.mssql-bind.php
0
 
LVL 3

Author Closing Comment

by:NeilT
ID: 31567923
Apologies for delay in grading, just back from hols
Neil
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now