Please download the latest version by yourself. A copy of PHPSpreadsheet is not included in the zip file.The first row is the column headers and the subsequent ones are the actual data themselves.įirst, here is the download link to the source code as promised. The PHPExcel parser returns excel data as array of arrays. $columns = implode(",", array_values($data)) $data = $obj->getActiveSheet()->toArray(null, true, true, true) The php script loads PHPExcel library, establish connection to mysql database, read the entire excel file, store the rows in associative arrays, loop through it and insert into the database. Step 4) Create index.php file and add the below code to it. Step 3) Create an excel file 'empdetails.xlsx' and add some data to it. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 CREATE DATABASE IF NOT EXISTS `db_employee`
This is the one I'm going to use for the demo. Step 2) Create necessary database and table in mysql. Step 1) First download PHPExcel library, unzip and move it to your root folder. Here goes the step by step process for inserting excel to
Now establish mysql connection, read through excel rows one by one and insert into database. Here I'm going to assume the excel column headers matches the table fields. You have a mysql table and an excel file with some data to be stored in db. How to Insert Excel File into MySQL using PHP? As for this tutorial I'm going to focus on dealing with excel file.Ĭome, let me show you how to read excel file and store data into mysql db with php.
Simple! But I'm not going into greater detail about the process here. Just save your excel file as csv format, then read it with native fgetcsv() function and insert into db. How do you insert data from Excel to MySQL using PHP?įor those who don't like using third-party library here's a way to do it with core php alone.How read Excel file and insert into database in PHP?.STEP 2) DUMMY DATABASE TABLE & EXCEL FILE.How to Insert Excel File into MySQL using PHP?.