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

x
?
Solved

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

Posted on 2009-04-08
3
Medium Priority
?
183 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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.
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.

688 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