473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

putting a word doc in a mysql db?

This one has been bugging me for months everytime i've tried i've had
to give up and do something else. Anyone know how to do this, any help
would be much appreciated.

I think that I need to use a blob field is that correct? But from then
on im stuck.

Kind regards

Marc

Jan 14 '06 #1
5 2382
monomaniac21 wrote:
This one has been bugging me for months everytime i've tried i've had
to give up and do something else. Anyone know how to do this, any help
would be much appreciated.

I think that I need to use a blob field is that correct? But from then
on im stuck.

Kind regards

Marc

yes, you have to use blod. You have to read file into any variable and
then just use insert into you blob field.
Jan 14 '06 #2
Marc,

you can put your binary data into a blob field (say named doc) using
straight sql just like:

$sql = 'update mytable set doc=0x';
$fh = fopen($_FILES['userfile']['tmp_name'],'rb');
while(true) {
$chunk = unpack('H*chunk',fread($fh,512));
$sql .= $chunk['chunk'];
if(strlen($chunk['chunk'])<512) break;
}
fclose($fh);

where $_FILES['userfile']['tmp_name'] is the file coming with a post
request.
But this is just appropriate for personal use as it is consuming lots of
ram and costs performance on both sides, the php engine and the
database. Make also sure that driver specific settings allow huge query
strings.
Other solutions depend on the database and databasedriver
you use but should be much more efficient.
Cheers,

robert
Jan 14 '06 #3

Robert Lummert wrote:
Marc,

you can put your binary data into a blob field (say named doc) using
straight sql just like:

$sql = 'update mytable set doc=0x';
$fh = fopen($_FILES['userfile']['tmp_name'],'rb');
while(true) {
$chunk = unpack('H*chunk',fread($fh,512));
$sql .= $chunk['chunk'];
if(strlen($chunk['chunk'])<512) break;
}
fclose($fh);


Robert how do you then retrieve this data, as a word document that can
be opened right away?

Kind regards

Marc

Jan 14 '06 #4
Following on from Robert Lummert's message. . .
But this is just appropriate for personal use as it is consuming lots of
ram and costs performance on both sides, the php engine and the
database. Make also sure that driver specific settings allow huge query
strings.
Other solutions depend on the database and databasedriver
you use but should be much more efficient.
Cheers,

ABSOLUTELY.
Be prepared for performance/capacity issues if you do things this way.


--
PETER FOX Not the same since the pancake business flopped
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jan 14 '06 #5
It will be in binary in the database. Use mysql_escape_string() to encode
the data and stripslashes() to decode the data.
<?php //viewdoc.php
$q=mysql_query("SELECT doc FROM mytable WHERE doc_id=$_GET[id]", $link);
if ($row=mysql_fetch_array($q)) {
header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="download.doc"');
echo stripslashes($row['doc']);
}
?>

and to insert data into the table (the stuff at the bottom only updates),
$sql = 'INSERT INTO mytable(doc) VALUES (0x';
$fh = fopen($_FILES['userfile']['tmp_name'],'rb');
while(true) {
$chunk = unpack('H*',fread($fh,512));
$sql .= $chunk['chunk'];
if(strlen($chunk['chunk'])<512) break;
}
fclose($fh);
$sql .= ")";
mysql_query($sql, $link);
wouldn't that unpack be simply unpack('H*',fread($fh,512))) ? chunk would
really mess things up when unpack tries to interpret it wouldn't it?

"monomaniac21" <ma********@msn.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Robert Lummert wrote:
Marc,

you can put your binary data into a blob field (say named doc) using
straight sql just like:

$sql = 'UPDATE mytable SET doc=0x';
$fh = fopen($_FILES['userfile']['tmp_name'],'rb');
while(true) {
$chunk = unpack('H*chunk',fread($fh,512));
$sql .= $chunk['chunk'];
if(strlen($chunk['chunk'])<512) break;
}
fclose($fh);
$sql .= " WHERE doc_id=$docid";
Robert how do you then retrieve this data, as a word document that can
be opened right away?

Kind regards

Marc

Jan 15 '06 #6

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

Similar topics

0
by: Cleber Hostalácio de Melo | last post by:
Hi, I need to change the stop word file used by the MySQL in fulltext seach. The documentation (www.mysql.com/doc/en/Fulltext_Fine-tuning.html) explains how to inform to MySQL the new stop...
3
by: intl04 | last post by:
Is it possible to create a Word form as the data entry form for an Access database? I didn't see any reference to this possibility in my Access books, so I'm sorry if this is a question that is...
2
by: danielboendergaard | last post by:
Hey Im making a homepage in php. I use a html form to put data into mysql and i want to make some buttons which inserts user input values into a textarea. I have used a button like this: <input...
2
by: Peschtra | last post by:
Hello -- Perhaps this is a silly question, but is the word "change" a php or MySql command? I had a script that wouldn't work with the a field called "change" in it, but when I removed that...
2
by: David Dawson | last post by:
I have forgotten a lot about SQL and would like to be (gently) reminded how to do this: In a MySQL query on the database (one table with 15 variable length fields, I want to put each field into a...
2
by: Dámaso Velázquez Álvarez | last post by:
Hi! I am working with mysql server 5.0 an I have an Index in a database table, but I need to index the word 'once'. My index it's not indexing it because once is a number... How can I...
6
by: Justin | last post by:
Hi all, i need some help over here... i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a...
2
by: macnimation | last post by:
Hi, I have created a Search Input that when a word is typed, I get a result of records based on all or part of the word, which is fine, and this is based across several Fields. Any Table fields...
2
by: klimmer | last post by:
Hello, I'am used to work with PHP and MySQL on webbased application. I have to make for my colleagues a program that have to follow a few dessistions (path) like a flowchart. The result shood...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.