Re: PHP/MySQL LOAD DATA LOCAL INFILE...
| From: | Koos van den Hout | Date: | Thu, 07 Sep 2000 19:45:12 +0000 |
| Subject: | Re: PHP/MySQL LOAD DATA LOCAL INFILE... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-2711@lists.php.net to get a copy of this message | ||
Quoting joe@jWebMedia.com who wrote on Thu, Sep 07, 2000 at 02:27:32PM -0500:
> Before I say anything, let me say I checked the archives, found info
> about this, but seem to be hitting a different problem than usual...
This is a lot more of a MySQL thing then a PHP thing. Maybe that
determines the direction to look into.
You are using a *very* MySQL specific function. If I would try something
like this from PHP, I'd read the file and separate it into fields using
fgetcsv, and then create the correct insert statements to insert the data
into the database.
> exec("mv $upload $base/data/$media_name");
> chmod($base."/data/".$media_name, 0755);
>
> mysql_db_query($database, "LOAD DATA LOCAL INFILE
> \"/full_path_to_file_here\" into table my_table FIELDS TERMINATED BY ','
> LINES TERMINATED BY '\"'
Interesting statement here. Between records there is a " ? No newline
as line separator ?
fgetcsv from PHP does this much better.
> (program_title, program_term, program_year,
> program_dates, location, program_desc_1, program_desc_2, program_desc_3,
> program_desc_4, academic_desc_1, academic_desc_2, academic_desc_3,
> academic_desc_4, courses_1, courses_2, courses_3, courses_4, faculty_1,
> faculty_2, faculty_3, faculty_4, academic_credit_1, academic_credit_2,
> academic_credit_3, overseas_institution, accommodations_1,
> accommodations_2, accommodations_3, meals_1, meals_2, excursions_1,
> excursions_2, excursions_3, cultural_activities_1,
> cultural_activities_2, cultural_activities_3, cultural_activities_4,
> airfare, program_fee, program_includes_1, program_includes_2,
> program_includes_3, program_includes_4, program_includes_5,
> program_doesnt_include_1, program_doesnt_include_2,
> program_doesnt_include_3, program_doesnt_include_4, payment_sched_1,
> payment_sched_2, sponsoring_institution, eligibility_1, eligibility_2,
> how_to_apply_1, how_to_apply_2, for_more_info_1, for_more_info_2,
> keywords, images)");
From a database designer standpoint this makes me say 'Eeeeeeeeeeeeeeeeew'
as a design for a table. MySQL isn't really a good relational database
management system but the above violates the basic rules of database
design. But that's outside the scope of php-db.
Koos
--
Koos van den Hout, PGP keyid RSA/1024 0xCA845CB5 via keyservers
koos@kzdoos.xs4all.nl or DSS/1024 0xF0D7C263 -?)
Fax +31-30-2817051 Visit my site about books with reviews /\\
http://idefix.net/~koos/ http://www.virtualbookcase.com/ _\_V