473,771 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ODBC and storing binary data (specially BLOB)

I'm abit confused on how to work with binary data with an ODBC
connection (My database is DB2 btw)

Say I have a table like
CREATE TABLE EJWLIB.BLOBTEST (
ID NUMERIC(5) NOT NULL,
FILENAME VARCHAR(128) NOT NULL,
BINARY BLOB(2M) )

Now I (I assume this is the correct method) insert data in the
following method

$MyInputStream = fopen($MyFilena me, "rb");
$binary_data = fread($MyInputS tream, filzesize($MyFi lename));
// Do I need to check to make sure the file is not greater than the
alloted 2M or will the SQl statement just fail if I try to insert
something larger?

$query = "INSERT INTO $MYTABLE VALUES ($RECORD_ID, '$MyFilename', ?)";
$prepared_sql = odbc_prepare($M yConnection, $query);

$result=odbc_ex ecute($prepared _sql, array("$binary_ data");

// $result never seems to be false even if I try to insert more than 2M
of binary data
// When I attempt to insert more than 2M it seems to simply skip
inserting the entire row itself but doesn't display any error message
if ($result === false)
echo "Failed SQL statement $query " . odbc_errormsg() ;

Now, when I want to retrieve my binary data I do so like

$query = "SELECT * FROM $MYTABLE WHERE ID = ?";
$prepared_sql = odbc_prepare($M yConnection, $query);
$result = odbc_execute($p repared_sql, array("$RECORD_ ID"));

while (odbc_fetch_row ($result)) {
$filename = odbc_result($re sult, "FILENAME") ;
$OutputStream= fopen($filename , "wb");

$binary = odbc_result($re sult, "BINARY");
fwrite($OutputS tream,$binary);

fclose($OutputS tream);
}

The other issue I have is the max amount of binary data I seem to be
able to retrieve is 4K. Any binary data i insert with the above method
when I attempt to retrieve it I get the correct resutls however I only
get the first 4K (or the entire file if it was originally under 4K).
Any ideas?

Nov 30 '05 #1
0 2349

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5706
by: Juergen Gerner | last post by:
Hello Python fans, I'm trying and searching for many days for an acceptable solution... without success. I want to store files in a database using BLOB fields. The database table has an ID field (INT, auto_increment), an ORDER field (INT, for knowing the right order) and a "normal" BLOB field. It is planned to split large files in 64k-parts and sort these parts by the ORDER field. Here's some pseudo code how I wanted to implement this...
2
6443
by: David Horowitz | last post by:
Hi folks, I want to be able to store and retrieve UNSAVED Word documents as BLOBs. I got all the info for storing them if they're already saved on the file system. But what if they're not already saved? I could save them to a temp file first and then make it a blob, but I'd rather not put them on the file system at all. I could use Document.Contents to get the Range object for the whole doc and then BLOB that, but I'm not sure that would...
11
3252
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will just display it below: The following code contains the script to process the uploaded file, the form to upload the file and then a few links to view the file from
3
4726
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around 2Mb) are stored in BLOB column. The amount of documents for the first year should not exceed 5/6 Giga, but I cannot make prevision for the next years. Those documents are mainly just accessed (update and delete are not so
4
9903
by: Hazzard | last post by:
What is the best way to do this? Binary with 0 representing off and 1 on? Int16 with 1 representing first button, 2 the second, 3 ... varchar with a character values at certain positions in the string representing radio button values. Thanks, -hazz
3
2924
by: Chris | last post by:
Hi all, I am trying to use System.Data.ODBC to insert a file into a binary field in SQL Server 2000. Now, before you yell at me, the reason I am doing this is that I am only writing intitial code against SQL, but this app will need to be able to run against any ODBC compliant DB, so I am also not using stored procedures. I have tangles with this for hours, but I cannot seem to figure out how to just read the contents of a file off...
0
2705
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
8
3855
by: Godzilla | last post by:
Dear all, I cannot find a solution for my problem with inserting a blob object (>4000 in length) into an ORACLE database via ODBC. I have tried the two ways of inserting the blob object (a zip file): 1)
3
7552
by: rustyhowell | last post by:
I'm trying to store binary data in a sqlite database and call into the db using pysqlite 3. What I've got so far is this: import sqlite con = sqlite.connect(DB_PATH) cur = con.cursor() query = """create table t1( ID INTEGER PRIMARY KEY, data BLOB );"""
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.