Current location: Hot Scripts Forums » Programming Languages » PHP » How to write a php script to load a text file into a table automatically?


How to write a php script to load a text file into a table automatically?

Reply
  #1 (permalink)  
Old 02-11-04, 01:24 PM
xmxpcom xmxpcom is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
How to write a php script to load a text file into a table automatically?

I have a text file need to be loaded into a table.

1. How could I write a php program to load the text file into a table?
2. How Could I load the text file automatically every one minute?
Since I do not have access to my ISP server, I guess I can not use cron job to do it.
__________________
Just $90 for Skyfi XM receiver. Visit www.xmxp.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-12-04, 01:21 AM
fattycat fattycat is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
This may help

This will load a text file into a database table.



$db_host="localhost";
$db_username="your_sql_username";
$db_password="your_sql_password";
$db_database="your_database_name";

$some_file = 'your_textfile.txt';
$fp = fopen($some_file, "r");
$em_footer = fread($fp, filesize($filename));
fclose($fp);

mysql_connect($db_host,$db_username,$db_password);
@mysql_select_db($db_database) or die( "Unable to select database");

$query = "INSERT INTO your_database_table (fieldone, fieldtwo) VALUES ('$valone, '$valtwo)";
mysql_query($query);
mysql_close();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-12-04, 09:37 AM
xmxpcom xmxpcom is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
(quote)
$query = "INSERT INTO your_database_table (fieldone, fieldtwo) VALUES ('$valone, '$valtwo)";

Thank you for your code. How Do I related ('$valone, '$valtwo)" to the fields in the text file, should be the first row of the text fie be field name?

Please advice.
__________________
Just $90 for Skyfi XM receiver. Visit www.xmxp.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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 code to edit a text file mdhall Script Requests 12 12-23-10 05:03 AM
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
php write to file tiny Script Requests 2 01-14-04 10:12 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM
PHP - Dir listing and write to file NickyWhicko PHP 4 08-24-03 03:42 AM


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