Jump to content


Photo

Export data from Excel to MySql


  • Please log in to reply
2 replies to this topic

#1 Whaih

Whaih
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 07 March 2006 - 10:31 AM

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?



#2 freddixon

freddixon
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 07 March 2006 - 11:17 AM

[!--quoteo(post=352442:date=Mar 7 2006, 10:31 AM:name=Whaih)--][div class=\'quotetop\']QUOTE(Whaih @ Mar 7 2006, 10:31 AM) View Post[/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]


#3 freddixon

freddixon
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 07 March 2006 - 11:30 AM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users