Tekforums

Chat => Entertainment & Technology => Topic started by: GroovyPigThing on April 10, 2006, 09:15:01 AM

Title: php/MySQL Question
Post by: GroovyPigThing on April 10, 2006, 09:15:01 AM
I have an excel spreadsheet with about 500 rows that i want to insert into a MySQL table. Is there a quick and easy way to do it?

Cheers
Title: Re:php/MySQL Question
Post by: Sweenster on April 10, 2006, 10:13:55 AM
There are definately programs that do it, like navicat, can also be done by php.

Never done it myself but just look around on google and you will find a method
Title: Re:php/MySQL Question
Post by: Christopher Monkey on April 10, 2006, 12:48:50 PM
You could just write a small bit of code in excel


Function insert_to_MySQL()

Dim oApp as MySQL.Application
Dim oTab as oApp.Table
Dim iTemp as Integer

set oApp = New MySQL.Application
set oTab = oApp.Tables.Add("NewTableName")

iTemp = 1

Do While Not Range("a" & iTemp) = ""
    DoCmd.RunSQL("SELECT INTO " & oTab & " VALUES(" & Range("A" & iTemp & ")" & " & Range("B" & iTemp & ")" & " & Range("C" & iTemp & ")" & " & Range("D" & iTemp & ");")
    iTemp = iTemp + 1
Loop

End Function


The syntax for MySQL may be wrong in that.... ive not got it installed so couldnt reference it!
Title: php/MySQL Question
Post by: GroovyPigThing on April 10, 2006, 13:09:40 PM
cheers for that, Ive managed to do it now :)
Title: Re:php/MySQL Question
Post by: M3ta7h3ad on April 10, 2006, 13:34:57 PM
Or... you could just export to CSV, and import using phpMyAdmin (pretty sure it can do that)
Title: php/MySQL Question
Post by: Christopher Monkey on April 10, 2006, 15:06:27 PM
How did you do it?
Title: php/MySQL Question
Post by: GroovyPigThing on April 10, 2006, 17:05:20 PM
i only needed one column of data to go into a table so i just transposed the column into a row in excel and exported it to CSV and then just pasted it into a form i wrote that exploded the huge long string into an array and added everything from there.

not pretty but it was quick and since I only needed to do it once I decided I couldnt be bothered with a prettier way :p

thanks for your help though - might play with that sometime and see if I can make it work :)