473,382 Members | 1,386 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,382 software developers and data experts.

Insert text file in a text field

Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab

Oct 18 '07 #1
10 6434
On Thu, 18 Oct 2007 18:36:59 +0200, <el********@yahoo.itwrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");
--
Rik Wasmus
Oct 18 '07 #2
On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus
<lu************@hotmail.comwrote:
On Thu, 18 Oct 2007 18:36:59 +0200, <el********@yahoo.itwrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?


mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");
Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus
Oct 18 '07 #3
On Oct 18, 6:36 pm, electri...@yahoo.it wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab
I wrote a tutorial on uploading files into a mysql database.
You can read it here :http://wiki.greenquery.com/doku.php?
id=understanding_php_classes#creating_uploadhandle r

I hope it's for some help to you.

//Michael

Oct 18 '07 #4
On 18 Oct, 17:36, electri...@yahoo.it wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

2) How can I insert a microsoft word file into a BLOB field of a
table ?

Please, could you help me with a simple example ?

Thank you .

Fab
Do not multi-post. Cross-post if you must but don't multi
post It wastes people's time. http://www.blakjak.demon.co.uk/mul_crss.htm.

You have had answers from people on 2 different groups. If you had
cross posted instead of multi-posting, everyone would have seen that
the question had been answered.

Oct 19 '07 #5
On 18 Ott, 19:33, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus

<luiheidsgoe...@hotmail.comwrote:
On Thu, 18 Oct 2007 18:36:59 +0200, <electri...@yahoo.itwrote:
Hallo,
I have 2 questions:
with php and mysql :
1) How can I insert a text file into a TEXT field of a table ?
2) How can I insert a microsoft word file into a BLOB field of a
table ?
Please, could you help me with a simple example ?
mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents('/path/to/file'))."')");

Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus

Thank you very much .

Another question:
after I put a text file in a text field,
then, how can I read this field content and put it into
a php variable ?

Many thanks .

Fabrizio

Oct 19 '07 #6
el********@yahoo.it wrote:
On 18 Ott, 19:33, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>On Thu, 18 Oct 2007 19:29:54 +0200, Rik Wasmus

<luiheidsgoe...@hotmail.comwrote:
>>On Thu, 18 Oct 2007 18:36:59 +0200, <electri...@yahoo.itwrote:
Hallo,
I have 2 questions:
with php and mysql :
1) How can I insert a text file into a TEXT field of a table ?
2) How can I insert a microsoft word file into a BLOB field of a
table ?
Please, could you help me with a simple example ?
mysql_query("INSERT INTO tablename (fieldname) VALUES
('".mysql_real_escape_string(file_get_contents ('/path/to/file'))."')");
Hmmm,
or: mysql_query("INSERT INTO tablename (fieldname) VALUES
(LOAD_FILE('/path/to/file'))");

For this you'd have to make sure:
- the database is on the same host as the file
- you have the FILE privilege
- the file is readable
- the filesize is less than max_allowed_packet bytes

--
Rik Wasmus


Thank you very much .

Another question:
after I put a text file in a text field,
then, how can I read this field content and put it into
a php variable ?

Many thanks .

Fabrizio

http://www.php.net/manual/en/ref.mysql.php

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 19 '07 #7
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?
textarea value="<?php echo thefile; ?>" something like that
>
2) How can I insert a microsoft word file into a BLOB field of a table ?
wouldn't it be more practical to just store the file's path instead of the file itself?
>
Please, could you help me with a simple example ?

Thank you .

Fab
Oct 19 '07 #8
Henri wrote:
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
He's talking about a table in a SQL database.
>2) How can I insert a microsoft word file into a BLOB field of a table ?

wouldn't it be more practical to just store the file's path instead of the file itself?
Not necessarily. Often times I'll store files in a database. A lot of
good reasons to do so (which should be discussed in a SQL newsgroup).
>Please, could you help me with a simple example ?

Thank you .

Fab


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 19 '07 #9
Henri wrote:
On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
>2) How can I insert a microsoft word file into a BLOB field of a table ?

wouldn't it be more practical to just store the file's path instead of the file itself?
Actually it isn't.I ended up with EVERYTHING - files and images - in the
database simply because backing up the database then backs up EVERYTHING.

But I wouldn't use a text area to input a file..use the FILE input command.
>Please, could you help me with a simple example ?

Thank you .

Fab
Oct 19 '07 #10
On Fri, 19 Oct 2007 23:26:07 +0100, The Natural Philosopher wrote:
Henri wrote:
>On Thu, 18 Oct 2007 09:36:59 -0700, electric_r wrote:
>>Hallo,

I have 2 questions:

with php and mysql :

1) How can I insert a text file into a TEXT field of a table ?

textarea value="<?php echo thefile; ?>" something like that
>>2) How can I insert a microsoft word file into a BLOB field of a table
?

wouldn't it be more practical to just store the file's path instead of
the file itself?

Actually it isn't.I ended up with EVERYTHING - files and images - in the
database simply because backing up the database then backs up
EVERYTHING.
ok, good point. I was just not thinking in terms of back ups.
But I wouldn't use a text area to input a file..use the FILE input
command.
that was my misanderstanding the first question.
>
>>Please, could you help me with a simple example ?

Thank you .

Fab
Oct 20 '07 #11

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

Similar topics

5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
17
by: NuB | last post by:
I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank? example: I have 5 textboxes, and a user can leave some...
3
by: Alexander Widera | last post by:
Hi, i connect to a ms sql2000server via SqlConnection. if i make an SqlCommand "INSERT INTO mytable (mytext) VALUES (@mytext)" (or i make an update), and i pass the parameter @mytext a simple...
11
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
6
by: Ted | last post by:
I used bcp to produce the apended format file. How can it be modified to recognize the quotes that surround the text fields and not insert the quotes along with the text? Invariably, the first...
0
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.