How to fetch the excel sheet data and save into php mysql database?

fetch the excel sheet data and save into php mysql database


Hello, welcome to therichpost.com. In this post, I will tell you,  How to fetch the excel sheet data and save into php mysql database? I personally like php ver much. PHP is the best web language. There are many cms and frameworks in PHP and WordPress is the best example. facebook also used PHPin it.

Today we will fetch excel sheet data with the help of excel_reader php library and save that data into php mysql database.

Here is the excel file sheet look image:


And that data, will save in php mysql database and here is also working image:


Here is the working and tested code for it:
//First Create Test database and user table in that database

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root');
define('DB_DATABASE', 'test');

$connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);


require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("example.xls");
$rows = $data->sheets[0]['numRows'];
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
  if(count($data->sheets[$i][cells])>0) // checking sheet not empty
    for($j=1;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
      $name = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
      $email = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
      $query = "insert into user(name,email) values('".$name."','".$email."')";

 There are so many code in PHP and i will let you know all. Please do comment if you   any query related to this   post.   Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL