473,657 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2394
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($chun k['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($chun k['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******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Jan 14 '06 #5
It will be in binary in the database. Use mysql_escape_st ring() 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_fet ch_array($q)) {
header("Content-Type: application/msword");
header('Content-Disposition: attachment; filename="downl oad.doc"');
echo stripslashes($r ow['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*',fre ad($fh,512));
$sql .= $chunk['chunk'];
if(strlen($chun k['chunk'])<512) break;
}
fclose($fh);
$sql .= ")";
mysql_query($sq l, $link);
wouldn't that unpack be simply unpack('H*',fre ad($fh,512))) ? chunk would
really mess things up when unpack tries to interpret it wouldn't it?

"monomaniac 21" <ma********@msn .com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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($chun k['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
2192
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 word file through the "ft_stopword_file" variable. But I could not find any reference to the layout of this file, for example, how to separate each stop word in the list?
3
3809
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 rather off-the-wall. I was asked to ask this question, to see if a Word form can be linked to an Access database and then emailed to various end-users for them to complete task requests using this form.
2
9655
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 type="button" value="Add Quote" onclick="document.getElementById('nyhed').value+=''"> The button works fine and insterts into the textarea. Although I want to make a button which onclick asks the user for a
2
1374
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 field it worked fine. Just wondering. Thanks,
2
6788
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 Bash variable so that I can handle each field as an entity. The query I have is something like this: mysql -e "use $database; select field1, field2, field3..., from Table1 where fieldN like '%something%';"
2
2121
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 configure Mysql or the index to index this word? My index is Fulltext type.
6
8643
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 link for the end users to download the word file? FYI, the database records are obtained by end users submitting the forms themselve and i saved it in my db... Thanx.
2
1587
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 that contain all or part of the word displays the record. SELECT * FROM tbmain WHERE Owner LIKE %SearchString% OR Status LIKE %SearchString% OR TaskSummary LIKE %SearchString% OR TaskDescription LIKE %SearchString% OR Type LIKE %SearchString% OR...
2
2237
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 be a word document from about, 150-250 pages. The chapters are, depending of the anwsers in the virtuel flowchart. Afterwoods there are more then 100 fields automaticaly filled in from excel tabels. What qind of fields are depending of the flow...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6164
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
5632
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
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.