Page 1 of 1

How to import the txt file to database table

Posted: Fri Jan 30, 2009 1:05 am
by prakumma
hi,
i am trying to import the text file into database table. but it is giving the error. in text file fields are First Name, Last Name, EmailId. In data.txt has some inforation about the users.


mohan, rao, rao@gmail.com.
johson, jee, jee@yahoo.com

i want to import into database. i am not getting how to read the entair data in the file. Please give some idea.

Regards,
Prakum.

Re: How to import the txt file to database table

Posted: Fri Jan 30, 2009 2:38 am
by it2051229
probably the sql statement in your text file has syntax error.

Re: How to import the txt file to database table

Posted: Fri Jan 30, 2009 2:40 am
by Benjamin
Post your code and the error... then we can help you.

Please use [ code ] tags.

Re: How to import the txt file to database table

Posted: Fri Jan 30, 2009 5:53 am
by mavieng
Use the following MySQL Query

Code: Select all

 
<?php
 
      mysql_query("LOAD DATA INFILE 'filename.txt' INTO TABLE 'tablename' FIELDS TERMINATED BY ','");
?>
 
Note:
1.Your table should have same number of fields as in your text file for proper import.
2.You have to store your text file in mysql/data directory before executing above command.