How to import the txt file to database table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prakumma
Forum Newbie
Posts: 3
Joined: Tue Aug 19, 2008 11:18 pm

How to import the txt file to database table

Post 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.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: How to import the txt file to database table

Post by it2051229 »

probably the sql statement in your text file has syntax error.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to import the txt file to database table

Post by Benjamin »

Post your code and the error... then we can help you.

Please use [ code ] tags.
mavieng
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 12:34 pm

Re: How to import the txt file to database table

Post 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.
Post Reply