Solved

Insert PDF file into DB2 BLOB field using PHP and SQL

Posted on 2004-10-15
5
11,206 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
ID: 12325693
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
ID: 12329842
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
ID: 12360892
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
ID: 12730109
I did give a good solution
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

838 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