PHP tool that parses .xlsx Excel files and bulk-imports their rows directly into a MySQL database.
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
.xlsxfiles. Legacy.xlsformat is not supported.
Clone the repository:
git clone https://github.com/Cyrus2401/php-excel-to-database-importer.git
cd php-excel-to-database-importer- Database credentials — Copy the example config file and fill in your details:
cp config.example.php config.phpThen edit config.php:
define('DB_HOST', 'localhost');
define('DB_NAME', 'your_database');
define('DB_USER', 'your_username');
define('DB_PASS', 'your_password');
⚠️ config.phpis listed in.gitignore— your credentials will never be pushed to GitHub.
- 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)
);- Excel file — Place your
.xlsxfile in the project root and update the filename inindex.php:
if ($xlsx = SimpleXLSX::parse('yourfile.xlsx'))Run the script via your local PHP server or a web server (e.g. Apache / WAMP / XAMPP):
php -S localhost:8000Then open your browser at:
http://localhost:8000/index.php
If the import succeeds, you will see:
Save Successfully !