Solved

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

Posted on 2009-04-08
3
176 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

746 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

14 Experts available now in Live!

Get 1:1 Help Now