yintong wrote:I am going to save data into database (phpMyAdmin)
Do you mean that you want to load the text file content into a "table" which reside in a "database" using the PhpMyAdmin interface?.... (

just giving you a little better concepts ).
- Do you have the table that will receive the data already defined in your database?
- what kind of field delimiters your text file use?... is a csv file or something different?
- Is any reason why you need to do that in PHP?... asking because normally is easier and probably faster to do that using line commands or even using the SQL Script option in PhpMyAdmin if that is the tool that you know better.
I normally use the "LOAD DATA INFILE" (Mysql) sentence, this is an example:
Code: Select all
LOAD DATA INFILE 'c:/subfolder/myfile.csv'
INTO TABLE mytable FIELDS TERMINATED BY ','
(mytable_field1,mytable_field2,.... mytable_fieldn,@mytable_datefield)
SET mytable_datefield = date_format(str_to_date(@mytable_datefield,'%m/%d/%Y'),'%Y/%m/%d');
this sentence can be modified in many ways to match your text file structure or, like in your case insert only the new added lines from your text file (using the "IGNORE" parameter).
In particular this command is normally way faster (20 times depending on conditions) than using regular "INSERT" (the sentence that you will need to use if you do the load programing with PHP), and with some expertize the performance could even be improved.
Here is the link to the LOAD DATA instruction if you want to take a look a it:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
miko