how to dump data from excel file in mysql database using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nattyravi
Forum Newbie
Posts: 3
Joined: Sat Dec 07, 2002 10:50 pm
Contact:

how to dump data from excel file in mysql database using php

Post by nattyravi »

hello everyone,
i want to take data from a Microsoft excel file using php. i need then dump this data in the mysql database.. i am using Appache web server.. can you please tell me how to do it ?? if anyone can get me the code, that would help me a lot.. i have searched a couple of sites but i could not find direct solution..
i have to achieve this functionality by wednesday... so please consider this urgent!! reply back.. Any help will be appreciated..

thanks,
ravi

Note: i know how to do it in ASP.. if anyone is interested in knowing how it is done using ASP and Access/SQLServer i can tell them..
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

If you dont need it to update automatically, save your Excel file in CSV format (Comma Seperated Values).

There is a function in PHP for reading CSV, fgetcsv, http://www.php.net/manual/en/function.fgetcsv.php, or I think you can do it with phpMyAdmin.

I'm not sure how you can set it automatically to save as CSV, probably through ActiveX.

Or, you could load Apache with ASP, and combine your PHP/ASP files somehow. Oh, Oh! Use DSN or ODBC to connect ASP to your MySQL database.
nattyravi
Forum Newbie
Posts: 3
Joined: Sat Dec 07, 2002 10:50 pm
Contact:

Post by nattyravi »

thanks a lot f1nutter,
i will get back to you soon if i encounter any problems..
bye
maperen
Forum Newbie
Posts: 2
Joined: Fri Apr 04, 2003 4:35 am

Excel to PHP parser class.

Post by maperen »

There is a commercial solution for parsing Excel file:
http://www.zakkis.ca/products/abc_excelparser/

This is a pure PHP class which parse Excel file of any Excel version into the PHP array structures. Certanly you can not get any embedded OLE objects on the Unix, but there are no any problems to get all worksheets data with its Excel formatting etc....

Good luck.

Regards,
Maxim.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

LOAD DATA INFILE is specifically designed to load data from files (including csv) very quickly - see manual mysql.com or use phpMyadmin, as suggested above (open a table and click the "insert file" option to run LOAD DATA, if I remember rightly).

I haven't used fgetcsv but I suspect LOAD DATA is a more efficient option to get the data into mysql particularly for a very large file.

If you have to do some php processing on the data fgetcsv might be the way to go - or you could get it into php after a LOAD DATA.
Post Reply