Entering a load of data troubles.
Posted: Tue Nov 16, 2004 2:38 pm
I'm wanting to add a load of data into my database and would appreciate advice as to the best way of doing it.
I've RTFM and it says this is one option:
If there's a better way then let me know!
Thanks!
I've RTFM and it says this is one option:
Except the LOAD DATA INFILE line doesn't work, any ideas? This is the error message:Adding a bunch of data
If you have a large amount of data to enter and it’s already in a computer file,
you can transfer the data from the existing computer file to your MySQL database.
The SQL query that reads data from a text file is LOAD. The LOAD query
requires you to specify a database.
Because data in a database is organized in rows and columns, the text file
being read must indicate where the data for each column begins and ends
and where the end of a row is. To indicate columns, a specific character separates
the data for each column. By default, MySQL looks for a tab character
to separate the fields. However, if a tab doesn’t work for your data file, you
can choose a different character to separate the fields and tell MySQL in the
query that a different character than the tab separates the fields. Also by
default, the end of a line is expected to be the end of a row — although you
can choose a character to indicate the end of a line if you need to. A data file
for the Pet table might look like this:
80 Part II: MySQL Database
Unicorn<TAB>horse<TAB>Spiral horn<Tab>5000.00<Tab>/pix/unicorn.jpg
Pegasus<TAB>horse<TAB>Winged<Tab>8000.00<Tab>/pix/pegasus.jpg
Lion<TAB>cat<TAB>Large; Mane on neck<Tab>2000.00<Tab>/pix/lion.jpg
A data file with tabs between the fields is a tab-delimited file. Another common
format is a comma-delimited file, where commas separate the fields. If your
data is in another file format, you need to convert it into a delimited file.
To convert data in another file format into a delimited file, check the manual
for that software or talk to your local expert who understands the data’s current
format. Many programs, such as Excel, Access, or Oracle, allow you to
output the data into a delimited file. For a text file, you might be able to convert
it to delimited format by using the search-and-replace function of an
editor or word processor. For a truly troublesome file, you might need to seek
the help of an expert or a programmer.
The basic form of the LOAD query is
LOAD DATA INFILE “datafilename” INTO TABLE tablename
And the line of code is points to: (the first line shown)Parse error: parse error, unexpected T_STRING in /home/qhwslos/public_html/testdatabase.php on line 13
Code: Select all
LOAD DATA INFILE "test" INTO TABLE test;
mysql_query($query) or die (mysql_error());
mysql_close();Thanks!