Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generalised script for loading tab file into MySQL table?

Status
Not open for further replies.

AndyatIES

Technical User
Jul 4, 2002
18
GB
I need a generalised script to refresh MySQL tables from a PHP page, ie:

1) Delete all records from a named MySQL table
2) Read in records from a named tab-separated file
3) Confirm Table update OK
(and presumably be repeatable to update a series of tables in one go, from a series of tab files.)

Anyone have one? You'd make my day!
 
1)
Code:
  $sql = mysql_query(&quot;delete from <table name>&quot;);
You may want to check feedback on that to make sure that worked, ie that $sql isn't null.

2)
Code:
  $sql = mysql_query(&quot;load data local infile \&quot;<file>\&quot; into \&quot;<table>\&quot;&quot;);
This reads a tab delimited file, and reads line-feeds as new records. Again, you may want to check the feedback, and make sure that it worked.

3) Rinse, repeat as necessary. As with checking the values, I think you can probably do a check to make sure they're not empty, if they are not empty, count the number of rows.

--
Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top