Current location: Hot Scripts Forums » Programming Languages » PHP » Files & Database ???


Files & Database ???

Reply
  #1 (permalink)  
Old 07-13-05, 09:31 AM
aniraka aniraka is offline
New Member
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Files & Database ???

Hello!! Daily I receive a text file with certain information. I need to read it, process it and present it in a web site. The first thought I had was, read and process the information using C++ for example, since it was easy to do, and create a html file with the information I need it (It will be on tables). Then I thought that it would be great if I could process the information and write it into a database, since I could have just one dynamic web page, but I have no idea how to read a text file and write the information I need into the data base.

Does anyone know how I could do such a thing?.. Maybe I could read a common text file using php, and then introduce the information into the database without using others tools, but It should be done once a day everyday (just once)…..

I have no idea how could I do ?!.... Could you help me?
Reply With Quote
  #2 (permalink)  
Old 07-13-05, 09:39 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
You would need to use cron jobs to automatically read it once a day, otherwise you would manually have to go to the script once a day to do it!

PHP Code:

<?php


//filename
$filename "file.txt";

$handle fopen($filename"r");

//data in text file is stored in $data
$data fread($handlefilesize($filename));

fclose($handle);

//now you can do anything you like with the data
//here we will just print it onto the screen
print $data;

?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #3 (permalink)  
Old 07-13-05, 11:41 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
You could also use file_get_contents()
PHP Code:

<?php


//filename
$filename 'file.txt';

//data in text file is stored in $data
$data file_get_contents($filename);

//now you can do anything you like with the data
//here we will just print it onto the screen
echo $data;

?>
Reply With Quote
  #4 (permalink)  
Old 07-13-05, 12:02 PM
aniraka aniraka is offline
New Member
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks - But

Thanks for your comments, let me try. However,... I wonder if I could run a php code as a cron job. I ask you because usually a php code is used on web pages and in this case it would run an application that it does not really anything to do with a web page, since It will run just to introduce the information into the database.
Reply With Quote
  #5 (permalink)  
Old 07-13-05, 12:52 PM
sszettella sszettella is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Run PHP as a cron job

PHP is a general purpose programming language, and can easily be run from a command line.

All you need to do (usually) is type "php myProgram.php" and you should be good to go. Cron will run the php executable with "myProgram.php" as an argument. Much as you might "cat myfile", where cat is the executable, and myfile is tha arguement.

Hope this helps
__________________
Steve Szettella
4word systems
http://www.4wordsystems.com
http://szettella.blogspot.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Simple, searchable book database max fischer Script Requests 0 05-14-05 01:00 PM
Save articals to files or database? webx2000i PHP 6 10-17-04 11:27 AM
Where are MySQL cache files? darkfreak PHP 4 06-21-04 12:30 AM


All times are GMT -5. The time now is 06:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.