Wednesday, July 10, 2024

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 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.

the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, 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.