Solved

Insert PDF file into DB2 BLOB field using PHP and SQL

Posted on 2004-10-15
5
11,137 Views
Last Modified: 2012-05-05
How can I insert PDF file into DB2 BLOB field using PHP and SQL?
0
Comment
Question by:The_Master_Chief
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Alan Warren
Comment Utility
Have a look at Lewies upload class, written in vbscript, uploads to a Jet db, but I expect it may be modified to suit your platform requirements, by changing the connection string.

Upload Files Without COM v3
Allows you to upload multiple files and fields without purchasing or registering COM objects.
http://www.lewismoten.com/LewiesCodeLibrary/Details.htm?folder=ASP/UploadFilesWithoutCOMv3

Alan
0
 
LVL 4

Accepted Solution

by:
Sicos earned 100 total points
Comment Utility
Hi,

You can find example codes on the IBM site...

http://www.developer.ibm.com/tech/sampdb2.html

Or another solution is to base64 encode youre file end put it in a string field.

The only thing that matters is that you make youre string field big enought

Greetings,
Sicos
0
 
LVL 2

Author Comment

by:The_Master_Chief
Comment Utility
Of the responses, the second one was moderately useful as it pointed to code samples from IBM, where I found some Java code that led to a few experiments, that were ultimately unsuccessful.
 
There are no specific references using PHP, IBM blames PHP and offers no solution, and apparently noone else has the same problem. PHP handles blobs just fine for MySQL
 
Some of the things we've tried:
include blob's content directly in SQL statement. Statement becomes more than a few Kb big, DB2 complains.
break up blob into segments, use INSERT for first segment, then try to UPDATE the field using CONCAT to append the subsequent mini-blobs. DB2 doesn't like CONCAT used this way.
taking a clue from some sample code found in a PDF doc from IBM [ref.1], put blob part of SQL statement inside a 'blob()' function/statement. DB2 seemed to like this, but when trying to retrieve the data it turned out that only a few bytes were being saved, hence the actual binary file was unusable or corrupted.
another code sample found in same doc included the declaration of a "file reference" and this reference was used in the SQL statement, as in "INSERT INTO table (blob_field) VALUES ( :file_reference )". The sample code at one point mentioned that this file reference declarations worked for C, C++, Java & Cobol *only*. Still I tried it with PHP, and DB2 cries foul on the first line of the declaration no matter how many variations of it I tried, and it goes like this:
$declaration =
 'BEGIN DECLARE SECTION;
  SQL TYPE IS BLOB_FILE mypdf;
  mypdf.name='.$filename.';
  mypdf.name_length='.strlen(filename).';
  mypdf.data_length='.filesize($filename).';
  mypdf.file_options=SQL_FILE_READ;
 END DECLARE SECTION;';

[ref.1] http://www.redbooks.ibm.com/redbooks/pdfs/sg245409.pdf
0
 
LVL 4

Expert Comment

by:Sicos
Comment Utility
I did give a good solution
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

13 Experts available now in Live!

Get 1:1 Help Now