How can I add a text file as a field value in MYSQL?
Posted by: fainleog (83.70.200.---)
Date: November 20, 2008 07:48PM

I have a simple table with an ID field and a TEXT field.
I understand a TEXT field can contain up to 64K characters.
I have several multi line simple text files created using Notepad.
I want to add these files as values in the table.
I want the first record to contain all of the text in the first text file, and so on for each text file.
So the vaue of the TEXT field in the table will be the concatenation of the lines in the Notepad text file.
Just an ascii string with the embedded line feed characters - I am hoping.
If I have twenty text files, I will have twenty records in the table.

Can this be done? If so, how, please? (yes, I am a learner!)

George

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: November 20, 2008 08:05PM

ud need to show me a sample of the text file. but from what i understand .. use php to read in the entire file as a string ... then post it to the table


if this is just a one off thing... then just open phpmyadmin and go to your table... click insert

copy the text file and paste it into the text field.. if you only have twenty to do this would be quickest..

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: fainleog (83.70.200.---)
Date: November 20, 2008 10:10PM

Thanks Steven.

The files are actually web pages. That is, text files containing html/php statements.

I will look at using php to read in the files and append the lines to a variable - is that what you are suggesting? Then insert the resulting variable into the table.
My main concern here is that I would lose the separation of the individual lines in the file.
I want at a later time to be able to reconstitute the web pages.
<thinks: I could insert a break symbol after each line - hhhmmmm>

This is not a once off exercise - it's part of a larger project.

George

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: November 20, 2008 10:16PM

cant you have 21 columns?

each line goes to a column....
then you dont need to worry

php strip tags works very well at taking out the php and html tags from the file...

id have to see the types of information being stored but remember mysql is extremely quick

20 rows per file or . 20 colums per file or 20 tables(1 per file)... this would run with no noticable delay..

use something such as <br> to seperate then lines if storing them all in one cell

or even better use an array.....

$file1[line1]=asfd;lsag;lkjsgkfajg;klj
$file1[line2]=lkjfdlfjlkfskjdfjkdlf

etc etc
$file2[line1]=slkafgjlskfg

etc

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: fainleog (83.70.200.---)
Date: November 21, 2008 12:04AM

Thanks again Steven.

I think I'll go with the table idea - a separate table for each web page (text file).
Each row is a line of text.
I had been put off by the possible number of tables - but this appears not to be a problem.

So, problem solved. Well, this one at least smiling smiley

George

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: November 21, 2008 12:09AM

no problem ,,, just thinking///
u could always use something like excel to open the webpage... then save it as a csv file and import it directly into the db.

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: toivo (---.belrs3.nsw.optusnet.com.au)
Date: November 21, 2008 10:12AM

Here is a function that returns the contents of a web page in a variable. If the read fails, it writes a message to the log file and returns FALSE.

function readPage( $url ) {
  $page = file_get_contents( $url );
  if ( $page === false ) {
  	  $msg = "readPage unable to read ".$url;
  	  error_log( $msg );
  	  return false;
  }
  return $page;
}

It needs the option allow_url_fopen to be enabled in the php.ini file.

Regards,

toivo
Sydney, Australia



Edited 1 time(s). Last edit at 11/21/2008 10:17AM by toivo.

Options: ReplyQuote
Re: How can I add a text file as a field value in MYSQL?
Posted by: fainleog (83.70.200.---)
Date: November 21, 2008 12:12PM

Thanks Toivo, will look at this approach. It is what I intended originally.

Much appreciated.

George

Options: ReplyQuote


Sorry, only registered users may post in this forum.