Export simple excel data into MySQL using PHP
Solution 1
Save this excel file as csv and run the following code with add your changings
$source = fopen('email.csv', 'r') or die("Problem open file");
while (($data = fgetcsv($source, 1000, ",")) !== FALSE)
{
$name = $data[0];
$email = $data[1];
mysql_query("INSERT INTO `table` (`name`,`email`) VALUES ('".$name."','".$email."') ");
}
fclose($source);
Solution 2
There is a
Iibrary named PHPExcel. With this library you can easily parse any excel file. Or you can export your file as csv and will be easier for you. php has native functions to handle csv files. You can use fgetcsv()
or str_getcsv()
.
Solution 3
Goto this link and download the php class that will read the excel file and return the array. This array will hold the all data written in excel file.
Its free...
You can also see the demo there.
I am already using it. Its definitely good.
Any other help on this you can freely ask to me.
Related videos on Youtube
ramesh
Updated on June 17, 2022Comments
-
ramesh almost 2 years
My client got a excel file with the following structure
name | email ---------------------------- Name | email here Name | email here Name | email here Name | email here Name | email here Name | email here
I would likes to make a MySQL database table according to this pattern and save the data into MySQL.
I am wonder how to do this. Also there is an option needed
We have to check that if that corresponding user had a correct email address, ie of the form @ .
Can we check the data as a loop while importing ?
Also how to convert this data to MySQL ?
-
Asad Saeeduddin over 11 yearsIs it feasible to convert to CSV first?
-
GregDAs @Asad said before, first convert to CSV and then use mysql to import the file into the database.
-
-
ramesh over 11 yearsis there any file size limitation ?
-
Mark Baker over 11 yearsExcept the limitation of PHP memory
-
Jestin about 4 yearsWith this code, I am able to get only the first row of the file.