Skip to content

Cyrus2401/php-excel-to-database-importer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-excel-to-database-importer

PHP tool that parses .xlsx Excel files and bulk-imports their rows directly into a MySQL database.


Description

php-excel-to-database-importer is a minimal PHP script designed to automate the import of Excel data into a MySQL database. It reads a .xlsx file row by row, maps each column to a database field, and inserts the records using PDO with transaction support for data integrity. Simple to set up and easy to adapt to any table structure.

Note: This tool only supports .xlsx files. Legacy .xls format is not supported.


Tech Stack

PHP MySQL


Installation

Clone the repository:

git clone https://github.com/Cyrus2401/php-excel-to-database-importer.git
cd php-excel-to-database-importer

Configuration

  1. Database credentials — Copy the example config file and fill in your details:
cp config.example.php config.php

Then edit config.php:

define('DB_HOST', 'localhost');
define('DB_NAME', 'your_database');
define('DB_USER', 'your_username');
define('DB_PASS', 'your_password');

⚠️ config.php is listed in .gitignore — your credentials will never be pushed to GitHub.

  1. Table — Make sure your target table exists. Example schema matching the default script:
CREATE TABLE infos (
    id        INT AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(100),
    lastname  VARCHAR(100),
    gender    VARCHAR(20),
    country   VARCHAR(100),
    old       INT,
    date      DATE,
    matricule VARCHAR(100)
);
  1. Excel file — Place your .xlsx file in the project root and update the filename in index.php:
if ($xlsx = SimpleXLSX::parse('yourfile.xlsx'))

Usage

Run the script via your local PHP server or a web server (e.g. Apache / WAMP / XAMPP):

php -S localhost:8000

Then open your browser at:

http://localhost:8000/index.php

If the import succeeds, you will see:

Save Successfully !

About

PHP tool that parses `.xlsx` Excel files and bulk-imports their rows directly into a MySQL database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages