Solved

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

Posted on 2009-04-08
3
180 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
[X]
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
  • 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 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:Neil Thompson
ID: 31567923
Apologies for delay in grading, just back from hols
Neil
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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