Author Topic: php/MySQL Question  (Read 1955 times)

php/MySQL Question
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

Re:php/MySQL Question
Reply #1 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

Re:php/MySQL Question
Reply #2 on: April 10, 2006, 12:48:50 PM
You could just write a small bit of code in excel

Code: [Select]

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!

php/MySQL Question
Reply #3 on: April 10, 2006, 13:09:40 PM
cheers for that, Ive managed to do it now :)

Re:php/MySQL Question
Reply #4 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)

php/MySQL Question
Reply #5 on: April 10, 2006, 15:06:27 PM
How did you do it?

php/MySQL Question
Reply #6 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 :)

0 Members and 1 Guest are viewing this topic.