Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-08
3
Medium Priority
?
185 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:Neil Thompson
  • 2
3 Comments
 
LVL 3

Author Comment

by:Neil Thompson
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 2000 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:Neil Thompson
ID: 31567923
Apologies for delay in grading, just back from hols
Neil
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

877 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