Re: PHP and insert an TXT file
| From: | pGw-tech | Date: | Wed, 19 Jul 2000 22:29:22 +0000 |
| Subject: | Re: PHP and insert an TXT file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7357@lists.php.net to get a copy of this message | ||
This all depends on the format of the data in your text file. You may need
to format it a little, or if your grabbing it from excel there shouldn't
much of a problem. You can load records using the LOAD DATA statement or
with the mysqlimport utility. LOAD DATA is used within your mySQL console
as follows:
mysql> LOAD DATA LOCAL INFILE "member.txt" INTO TABLE member;
This statement reads the contents of the data file member.txt and sends it
to the server to be load in the member table. Keep in mind, LOAD DATA LOCAL
won't work if your mySQL is older than version 3.22.15.
The mysqlimport utility acts as a command line interface to LOAD DATA. You
invoke mysqlimport from the shell, and it generates a LOAD DATA statement
for you:
% mysqlimport --local samp_db member.txt
mysqlimport derives the table name from the name of the data file. (It uses
everything up to the first period of the filename as the table name). For
example, member.txt would be laoded into the member table, and fubar.txt
would be loaded into the fubar table.
I suggest looking up both LOAD DATA and mysqlimport in the www.mysql.com
kb/manual as you will beable to find the additional syntax necessary for
properly importing your data. There are many options to play with such as
the ignore parameter which can choose to ignore the first line of your code
if you happen to have columns headers that you dont want to put in to your
database table.
If you are handy with php, you may just want to create a quick form that
will let you easily copy and paste your txt files in to the form and submit
the data in to your database. This might be faster if your data file
contains a lot of information that mysql is having problems importing using
the above options.
-----Original Message-----
From: Vadee Prudon <v.prudon@davidson.nl>
To: php-general@lists.php.net <php-general@lists.php.net>
Date: Wednesday, July 19, 2000 9:03 AM
Subject: [PHP] PHP and insert an TXT file
>Hai,
>
>Is it possible to upload an txt file and the mysql database
>will import the data out off the txt file into the database ?
>
>Something like this will put into my txt file
>
>#name
>this is the place of the data
>
>#description
>and add some text
>
>Does somebody has an example script ?
>
>Greetings Vadee
>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>