Hi, I have some urgent need to convert excel file into mysql table using php. In excel file and mysql there are three columns. What I want to do if open that file and submit should add all data into mysql table. Each row should go into one row in mysql table. any tutorial/script. thanks in advance for your help.
can we transfer data from excel to mysql database using php
Hi Imi_99
You can import any kind of CSV into MySQL. Try this page of the MySQL manual.
If you're having a problem with Excel in particular, I suggest exporting from Excel to TXT and trying again from there. Excel exports to TXT quite easily.
HTH
Norm
thnks for reply, will look at it tomorow. and will let u know how it goes.
Norm's way above would be best. If you need to do it through PHP, this method should work. Save your excel file as csv.
$rows = file('textfile.csv');
for($i = 0; $i < sizeof($rows); $i++) {
list($field1, $field2, $field3) = explode(',', $rows[$i]);
$query = "insert into tableName values ('$field1', '$field2', '$field3')";
mysql_query($query);
}
If you need to do it through PHP, the [man]fgetcsv[/man] function would be more reliable because it wouldn't break if there was a comma inside a field.
thnaks for all of your reply. What if i use php method(because i am using this on one of website to download xsl files) and there are comma in xsl file. will in that case explode will read that comma as well. i dont have much knowledge of explode that s why asking this question. thanks again
See reply above.