Solved

Insert PDF file into DB2 BLOB field using PHP and SQL

Posted on 2004-10-15
5
11,179 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
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…

776 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