How to Import CSV ,XLSX File Data Into MYSQL Database Using PHP

Blog
Spread the love

Follow The Below Step To Import CSV, XLSX File Data Into MYSQL Database Using PHP Spreadsheet Library.

  • Step 1: Create PHP Project
  • Step 2: Create database
  • Step 3: Create Table In Database
  • Step 4: Create Database Connection File
  • Step 5: Create HTML Form to Upload CSV, XLSX File
  • Step 6: Create PHP File To Import CSV,XLSX File Data Into Database

Step 1: CREATE PHP PROJECT

First of all, visit you web server directory and create a new project which name excel.

Step 2: Open the localhost/phpmyadmin and click top new button.

And write database name Image and click create button

Step 3: CREATE TABLE IN DATABASE

Step 4: CREATE Database Connection File

Create a File Name database.php and include into your PHP file.

Step 5: CREATE HTML Form To Upload CSV,XLSX File.

Create a simple html form which name is import.php

Output Like this-

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 6: Create PHP File to import CSV,XLSX File Data into database

Before follow this step , you check in your system composer is install or not.

Using this command check composer is install or not.

Composer –V

If composer install then go to Step 12:

If composer is not install then follow this step and install the composer.

Step 6: Open the any browser and write url is -> getcomposer.org when you click this link

Then open the screen like this

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Then click download button

Step 7: Then click on the composer-Setup.exe

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 8: Then click on “install for all users”.

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 8: Do not make any changes and click next button

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 9: You can see the installation location here click next.

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 9: Do not any changes click next

Step 10: click the install button

Step 11: then click next and finally click finish button

Then check composer is install using composer –V command

Step 12: After install the composer.

You run this command –

Composer require phpoffice/phpspreadsheet

Step 13: Then put it on PHP File code to import CSV,XLSX File Data into database and php file name is import_data.php

Step 14: Above html form I am using session

And the session file name is import_session.php and code

Step 15: Create excel sheet and columns should be in the excel sheet as many as in the database

Table structure like this-

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 16: Make excel sheet structure like this.

Import CSV, XLSX File Data Into MYSQL Database Using PHP

Step 18: After completed all the step go to form and choose the file and click the import button the file is imported successfully.

Conclusion:

Import data into database successfully.

bluethinkinc_blog

bluethinkinc_blog

2022-08-02

1

One Reply to “How to Import CSV ,XLSX File Data Into MYSQL Database Using PHP”

  • Avatar
    Chandan Tiwari

    Very nice

    2022-08-02 at 10:37 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Find More Blogs

Customize lead qualification for a seamless experience

Spread the love When the 2024 Release Wave 2 was launched,

Create a Custom Console Command in Spryker

Spread the love In Spryker, developers can create custom

SALESFORCE

Spread the love Salesforce is a cloud-based software

CRUD Operation in Spryker Backoffice with a Custom Module

Spread the love Spryker is a highly flexible and modular

How to create custom module on Spryker for Backoffice?

Spread the love Creating a custom module in Spryker

How to Install Spryker Project with Docker on Local Machine

Spread the love Spryker is a flexible and scalable commerce

How to Add a Custom Tab to the Customer Order Detail Page in Magento 2

Spread the love Adding a custom tab to the Order Detail

Exception Handling in Java

Spread the love Introduction – Exception:An unwanted

How to add custom less file in Magento2

Spread the love Source files *.css included into layout

Spring Boot Microservices

Spread the love Microservices architecture has become

bluethinkinc Blogs