473,513 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert blob

Having created a table with a longblob column, what is the insert syntax to
set the value of the longblob column? The data will be read from a file.
Jul 20 '05 #1
3 34314
"Frank Natoli" <fr****@nospam.com> wrote in message
news:eR*****************@newsread3.news.atl.earthl ink.net...
Having created a table with a longblob column, what is the insert syntax to set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$filedata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com
Jul 20 '05 #2
Thanks. Will this work if the data in $filedata is binary? Or must I base64
the data first?

"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:AN*******************@tornado.tampabay.rr.com ...
"Frank Natoli" <fr****@nospam.com> wrote in message
news:eR*****************@newsread3.news.atl.earthl ink.net...
Having created a table with a longblob column, what is the insert syntax to set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$filedata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com

Jul 20 '05 #3
If $filedata is a file on your filesystem -> 'c:\\images\\item_1.jpg' then
there appears to be no need to do anything. MySQL will load the data as-is.
If you 'read' $filedata into a variable first via fopen,fread,fclose then it
seems that you must either base64 or addslashes it before MySQL will except
it. In this case:

$data = '';
$fp = fopen($filedata,'r');
while (!feof($fp))
{
$data .= fread($fp,1024);
}
fclose($fp);
$slashed_data = addslashes($data);
UPDATE table_name SET filesize = $filesize, data = '$slashed_data' WHERE id
= 1
---

notice no LOAD_FILE, and quotes around the variable...
Norman
--
Avatar hosting at www.easyavatar.com
"Frank Natoli" <fr*********@worldnet.att.net.nospam> wrote in message
news:KV*****************@newsread2.news.atl.earthl ink.net...
Thanks. Will this work if the data in $filedata is binary? Or must I base64 the data first?

"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:AN*******************@tornado.tampabay.rr.com ...
"Frank Natoli" <fr****@nospam.com> wrote in message
news:eR*****************@newsread3.news.atl.earthl ink.net...
Having created a table with a longblob column, what is the insert syntax

to
set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$filedata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com

Jul 20 '05 #4

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

Similar topics

2
17769
by: Ole Hansen | last post by:
Hi, Is it possible to insert BLOB data without doing a select first? I have data available and want to insert a row with BLOB data. Should I use the callback function with OCILobWrite() or is...
2
6855
by: Niraj | last post by:
Hi, I am trying to do bulk insert of binary data (array of bytes) in an Oracle table. The data type of the table is BLOB. I am using Oracle Objects for OLE (OO4O) in C++. The binary data that I...
15
12287
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); ...
0
3128
by: Paul Kennedy | last post by:
I have a situation where I am utilizing code from MSDN to insert XLS files into a Microsoft Access Table in a column of Ole Object using VBA and DAO. That code also provides me with a method to...
11
22989
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
3
2890
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...
1
16181
by: shallowpool | last post by:
Can someone provide me the simple syntax necessary to insert or update to a row containing a single BLOB column, where the BLOB data will be obtained from a file? This is on a linux installation. ...
0
5166
by: Nesa | last post by:
Hi, I am accessing DB2 8.2 (Windows) via JDBC type 4 and am having troubles making Blob.setBinaryStream(long) work to update a BLOB column. Here is the excerpt of code that I am using: ...
2
5019
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5090
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...
0
4746
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...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1597
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 ...

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.