• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11382
  • Last Modified:

Insert PDF file into DB2 BLOB field using PHP and SQL

How can I insert PDF file into DB2 BLOB field using PHP and SQL?
0
The_Master_Chief
Asked:
The_Master_Chief
  • 2
1 Solution
 
Alan WarrenCommented:
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
 
SicosCommented:
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
 
The_Master_ChiefAuthor Commented:
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
 
SicosCommented:
I did give a good solution
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now