This repository contains a PHP command-line interface (CLI) script to read and process CSV files and store the data in a PostgreSQL database.
- Read CSV files
- Process and display CSV data in the CLI
- Store data into PostgreSQL
- PHP 8.3
- PostgreSQL 13 or higher
- Database name: postgres
- File name: users.csv (in the main directory)
Clone the repository:
git clone https://github.com/arnaldododo/php-read-csv-cli.git
Navigate to the project directory:
cd php-read-csv-cli
Install dependencies using Composer:
composer install
This project uses the following dependency:
doctrine/dbal
Run the script with the user_upload.php as the main file. Use --help option to show all the available options.
php user_upload.php --help
Dry run - This mode will parse the file without inserting to the database. The data will be displayed in a tabular format.
php user_upload.php --file=users.csv --dry_run
Create the users table. Run this before inserting data to the database.
php user_upload.php --create_table -u <username> -p <password> -h <host>
Parse the file and insert the data to the users table.
php user_upload.php --file=users.csv -u <username> -p <password> -h <host>
This project is licensed under the MIT License.
For more details, visit the repository.