For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2005 > importing a CSV file into two Mysql tables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author importing a CSV file into two Mysql tables
laredotornado@zipmail.com

2005-11-02, 6:56 pm

Hi, I was wondering how, using MySQL and PHP 4 (if necessary), could I
import a single CSV file to populate two MySQL tables. The tables are

CREATE TABLE MANUFACTURERS (
`MANUFACTURER_ID` int(10) unsigned NOT NULL auto_increment,
`NAME` varchar(64) NOT NULL default '',
PRIMARY KEY (`MANUFACTURER_ID`)
) TYPE=InnoDB AUTO_INCREMENT=3 ;

CREATE TABLE `PRINTERS` (
`PRINTER_ID` int(11) NOT NULL auto_increment,
`MANUFACTURER_ID` int(10) unsigned NOT NULL default '0',
`NAME` varchar(64) NOT NULL default '',
PRIMARY KEY (`PRINTER_ID`),
KEY `PRINTERS_IDX1` (`MANUFACTURER_ID`)
) TYPE = INNODB AUTO_INCREMENT=35;

ALTER TABLE `PRINTERS`
ADD CONSTRAINT `FK_PRINTERS` FOREIGN KEY (`MANUFACTURER_ID`)
REFERENCES `MANUFACTURERS` (`MANUFACTURER_ID`) ON DELETE CASCADE;

The CSV file has 2 columns

Manufacturer_Name,Printer_Name

I've seen a mysql import command when there's just one table and I'm
hoping there is a slight variation for two.

Thanks, - Dave

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com