Categories

Tuesday, December 3, 2024
#919814419350 therichposts@gmail.com
ExcelSheetPhp

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:

 excel-sheet-data

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

excel-sheet-data-into-mysql-php

Here is the working and tested code for it:
<?php
//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);

error_reporting(0);

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."')";
 
      mysqli_query($connection,$query);
    }
  }
 
}
?>

 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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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