Jump to content

Export data from Excel to MySql


Whaih

Recommended Posts

Hi there,

I'm new to php and i have trouble exporting data from Excel to MySql. There are available software application in the market that is able to do this but i would like to try it by coding in PHP. I know that i need to export the data to a csv file first before i put it in MySql. However i absolutely no idea where and how to start. Are there any kind soul to guide me along or are there any available sample coding for me to reference?

Link to comment
https://forums.phpfreaks.com/topic/4312-export-data-from-excel-to-mysql/
Share on other sites

[!--quoteo(post=352442:date=Mar 7 2006, 10:31 AM:name=Whaih)--][div class=\'quotetop\']QUOTE(Whaih @ Mar 7 2006, 10:31 AM) [snapback]352442[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi there,

I'm new to php and i have trouble exporting data from Excel to MySql. There are available software application in the market that is able to do this but i would like to try it by coding in PHP. I know that i need to export the data to a csv file first before i put it in MySql. However i absolutely no idea where and how to start. Are there any kind soul to guide me along or are there any available sample coding for me to reference?
[/quote]
Hi,

The easiest way is to create an SQL script file and then run it in one of the mysql clients such as mysqladministrator.

The following example is very simple but should give you the idea.

This part creates the database table

DROP TABLE IF EXISTS `database_name`.`table_name`;
CREATE TABLE `table_name`.`Types` (
`Type_ID` INT(10) NOT NULL,
`Type_Name` VARCHAR(25) NULL,
PRIMARY KEY (`Type_ID`);
)

This second part inserts the data into the database table, it is this bit that you have created from excel.

INSERT INTO `database_name`.`table_name`(`Type_ID`, `Type_Name`)
VALUES (1, "Dogs"),
(2, "Cats"),
(3, "Pigs"),
(4, "Donkeys");


Hope this helps,

Fred

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.