Import csv in PHP | How to import csv file in PHP? | How to Import CSV File Data into MySQL Database using PHP | Import a CSV File Using PHP and MySQL | How To Import CSV File Into MySQL Using PHP? | How to Import CSV Into MySQL Database Using PHP | Import CSV data into MYSQL using PHP


Import CSV in PHP & MySQL example

In most of the PHP web applications we stores data into MySQL database. We also export data in PHP or import data in PHP.

Here in this article I'm explaining how you can achieve the task of import CSV (comma-separated values)  into MySQL database with PHP.

In most of the projects uploading data or reports is a common task which we do so this article is very important for you to learn storing the CSV file data into MySQL.

A CSV file stores data in tabular format that can be separated by either comma(,) or semicolon(;). So this is very easy to read every row and insert all the rows into MySQL database.

Here we have HTML form code for uploading the CSV file.


Always remember if your form has POST method and you are uploading any file by the form you need to set the enctype like below code otherwise you file will not be uploaded.

I have created a csv database in MySQL and inside that I have users table like below query:

Here 'id' is the primary key which is auto incremented. We just need to import 3 columns data and that is name, email and phone.

Here is the code for MySQL database connection with PHP.

Here is the PHP code to import the CSV file into MySQL.


You also can explore how to export the MySQL data into excel/CSV in PHP Here.

Share This:

Leave a Reply

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