?
Solved

Insert PDF file into DB2 BLOB field using PHP and SQL

Posted on 2004-10-15
5
Medium Priority
?
11,294 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
[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
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 400 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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

771 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