how can we import data from excel to database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
makana
Forum Newbie
Posts: 1
Joined: Thu Aug 16, 2007 5:36 am

how can we import data from excel to database

Post by makana »

i need a example code where we can store teh data from excel sheet onto database
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you tried the various Excel Readers out there?
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Post by thinsoldier »

if it's just raw data and nothing else, no formatting, not graphs, not macro stuff
then just save it as a csv (comma separated value).

read the .csv with file() or file_get_contents()
http://php.net/file

file will turn the csv into an array



Code: Select all

// example:
// sun, moon, stars
// earth, fire, wind

// becomes

array
   [0] array
        [0] sun
        [1] moon
        [2] stars
  [1] array
        [0] earth
        [1] fire
        [2] wind
once you have array of data it's easy to loop through and put it all in a query.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fgetcsv() often works better.
Post Reply