PHP Classes

PHP CSV Import to MySQL: Import user data from CSV files into MySQL

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 171 All time: 8,838 This week: 63Up
Version License PHP version Categories
importcsvuser 1.0.0MIT/X Consortium ...5PHP 5, Databases, User Management
Description 

Author

This class can be used to import user data from CSV files into MySQL.

It takes the names of user data files in CSV format and imports it into tables in a MySQL database.

The class can also perform validation of the fields and data that comes from the CSV file, normalize the imported data and show basic reports on the user that was imported.

Picture of Sergii Pryz
  Performance   Level  
Innovation award
Innovation award
Nominee: 5x

 

Documentation

ImportCsvUser

PHP 7 ready SensioLabsInsight

Master

Build Status Coverage Status

Dev

Build Status Coverage Status

ImportCsvUser is a console application to help import User's data from CSV (comma separated value) to MySQL. Project is working for specific CSV structure where first row acts as a schema.

Additionally ImportCsvUser has:

  • validators
  • normalizers
  • import result
  • statistics

Requirements

Install

  1. Install and run Docker container
  2. Run inside Docker container `composer install`
  3. Run inside Docker container to create database `php bin/console doctrine:database:create`

Usage

ImportCsvUser supports commands:

* user:import-csv: import csv file to database * user:age-average: get age average

_Note_: all example command SHOULD be run inside import-web container.

user:import-csv

Please execute php bin/console user:import-csv -h to see how to use command.

Example 1

In that example is importing valid user file.

Please execute:

php bin/console user:import-csv --path ./doc/csv/user.valid.csv

As execution result:

Imported: 5
Skipped: 0

Example 2

In that example file contains some invalid rows.

Please execute command:

php bin/console user:import-csv --path ./doc/csv/user.valid.csv

As execution result:

Imported: 2
Skipped: 3
Line #1: Invalid parameter 'firstName'. This value should not be blank.
Line #1: Invalid parameter 'gender'. Choose a valid gender.
Line #5: Invalid parameter 'zipCode'. This value is too long. It should have 32 character or less.
Line #7: Invalid parameter 'birthDate'. This value is not a valid date.

user:age-average

Please run php bin/console user:age-average -h to see how to use command.

Example 1

Please execute command:

php bin/console user:age-average

As execution result:

Average male age: 32.12
Average female age: 30.26

File format

File SHOULD has delimiter , with enclosure ". First row in csv file is a schema. It is important the column name not an order.

Table bellow describes column name.

name/characteristics | firstname | infix | lastname | date of birth | gender | zipcode | housenumber --- | --- | --- | --- | --- | --- | --- | --- required | yes | no | no | no | no | no | no has normalizers | no | no | no | no | tim, lowercase | trim, uppercase | no data type | String[2-255] | String[0-45] | String[0-255] | Date[Y-m-d] | String['m', 'f'] | String[0-32] | String[0-255] example | Nick | ter | Tester | 1991-08-24 | m | 12010 | 9b

_Note_: column name SHOULD start form alphabetic character. It case if it's present some non alphabetic character it will be remove and application try to map columns with sanitized column name. For instance if the original column name # firstname ImportCsvUser converts it to firstname.

Skipped rows

Rows that has first column started with # are skipped.

Normalizers

Normalizers helps to clean users data of get the right format.

Here is a normalizer list:

  • zipcode: trim spaces, make uppercase

Validators

The data validators skip rows and write the report result with keeping process running.

There is a list of validators:

  • `firstname`: required, max length 255
  • `infix`: max length 45
  • `lastname`: max length 255
  • `gender`: `m` or `f`
  • `birthday`: date `yyyy-mm-dd`
  • `zipcode`: max length 32
  • `housenumber`: max length 255

Documentation

  1. Database EER: import_csv_user.png
  2. Uml class diagram: class.diagram.png
  3. Ideas: FUTURE.CANDIDATE.md
  4. CSV samples: csv

Contribution

If you find this project worth to use please add a star. Follow changes to see all activities. And if you see room for improvement, proposals please feel free to create an issue or send pull request. Here is a great guide to start contributing.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project and its community you agree to abide by those terms.

License

ImportCsvUser is licensed under the MIT License. Please see the LICENSE file for details.


  Files folder image Files (100)  
File Role Description
Files folder imageapp (4 files, 2 directories)
Files folder imagebin (2 files)
Files folder imagedev (1 directory)
Files folder imagedoc (3 directories)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (1 directory)
Files folder imagevar (1 file)
Files folder imageweb (7 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file FEATURE.CANDIDATE.md Data Auxiliary data
Accessible without login Plain text file LICENSE.txt Doc. Documentation
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:171
This week:0
All time:8,838
This week:63Up