PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (100)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-10-20 (24 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 108 This week: 4All time: 9,165 This week: 92Up
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.

  Performance   Level  
Name: Sergii Pryz <contact>
Classes: 10 packages by
Country: Ukraine Ukraine
Age: 35
All time rank: 145926 in Ukraine Ukraine
Week rank: 55 Up3 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 4x

 

Details

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  
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

  Files folder image Files  /  app  
File Role Description
Files folder imageconfig (9 files)
Files folder imageResources (1 directory)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Plain text file AppCache.php Class Class source
  Plain text file AppKernel.php Class Class source
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  app  /  config  
File Role Description
  Accessible without login Plain text file config.yml Data Auxiliary data
  Accessible without login Plain text file config_dev.yml Data Auxiliary data
  Accessible without login Plain text file config_prod.yml Data Auxiliary data
  Accessible without login Plain text file config_test.yml Data Auxiliary data
  Accessible without login Plain text file parameters.yml.dist Data Auxiliary data
  Accessible without login Plain text file routing.yml Data Auxiliary data
  Accessible without login Plain text file routing_dev.yml Data Auxiliary data
  Accessible without login Plain text file security.yml Data Auxiliary data
  Accessible without login Plain text file services.yml Data Auxiliary data

  Files folder image Files  /  app  /  Resources  
File Role Description
Files folder imageviews (1 file, 1 directory)

  Files folder image Files  /  app  /  Resources  /  views  
File Role Description
Files folder imagedefault (1 file)
  Accessible without login Plain text file base.html.twig Data Auxiliary data

  Files folder image Files  /  app  /  Resources  /  views  /  default  
File Role Description
  Accessible without login Plain text file index.html.twig Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file console Example Example script
  Accessible without login Plain text file symfony_requirements Example Example script

  Files folder image Files  /  dev  
File Role Description
Files folder imagedocker (2 files, 1 directory)

  Files folder image Files  /  dev  /  docker  
File Role Description
Files folder imageweb (1 file, 1 directory)
  Accessible without login Plain text file docker-compose.yml Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  dev  /  docker  /  web  
File Role Description
Files folder imageconfig (1 file)
  Accessible without login Plain text file Dockerfile Data Auxiliary data

  Files folder image Files  /  dev  /  docker  /  web  /  config  
File Role Description
  Accessible without login Plain text file supervisord.conf Data Auxiliary data

  Files folder image Files  /  doc  
File Role Description
Files folder imagecsv (2 files)
Files folder imagedb (2 files)
Files folder imageuml (2 files)

  Files folder image Files  /  doc  /  csv  
File Role Description
  Accessible without login Plain text file user.invalid.csv Data Auxiliary data
  Accessible without login Plain text file user.valid.csv Data Auxiliary data

  Files folder image Files  /  doc  /  db  
File Role Description
  Accessible without login Image file import_csv_user.png Icon Icon image
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  doc  /  uml  
File Role Description
  Accessible without login Image file class.diagram.png Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageAppBundle (1 file, 7 directories)
  Accessible without login Plain text file .htaccess Data Auxiliary data

  Files folder image Files  /  src  /  AppBundle  
File Role Description
Files folder imageCommand (2 files)
Files folder imageController (1 file)
Files folder imageEntity (1 file)
Files folder imageModel (1 file, 6 directories)
Files folder imageRepository (1 file)
Files folder imageResources (1 directory)
Files folder imageService (2 files)
  Plain text file AppBundle.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Command  
File Role Description
  Plain text file UserAgeAverageCommand.php Class Class source
  Plain text file UserImportCsvCommand.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Controller  
File Role Description
  Plain text file DefaultController.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Entity  
File Role Description
  Plain text file ImportUser.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  
File Role Description
Files folder imageApi (1 file, 6 directories)
Files folder imageBuilder (2 files)
Files folder imageCsv (2 files, 3 directories)
Files folder imageData (1 file)
Files folder imageException (3 files)
Files folder imageManager (1 file)
  Plain text file ObjectManager.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  
File Role Description
Files folder imageBuilder (2 files)
Files folder imageCsv (3 files, 2 directories)
Files folder imageData (2 files)
Files folder imageEntity (1 file)
Files folder imageManager (1 file)
Files folder imageRepository (1 file)
  Plain text file ObjectManagerInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Builder  
File Role Description
  Plain text file ImportResultFactoryInterface.php Class Class source
  Plain text file ImportUserFactoryInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Csv  
File Role Description
Files folder imageBuilder (4 files)
Files folder imageData (1 file)
  Plain text file ReaderFilterIteratorInterface.php Class Class source
  Plain text file ReaderInterface.php Class Class source
  Plain text file RowFilterInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Csv  /  Builder  
File Role Description
  Plain text file PathFactoryInterface.php Class Class source
  Plain text file ReaderFactoryInterface.php Class Class source
  Plain text file ReaderFilterIteratorFactoryInterface.php Class Class source
  Plain text file RowFactoryInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Csv  /  Data  
File Role Description
  Plain text file RowInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Data  
File Role Description
  Plain text file ImportResultInterface.php Class Class source
  Plain text file PathInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Entity  
File Role Description
  Plain text file ImportUserInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Manager  
File Role Description
  Plain text file ImportUserManagerInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Api  /  Repository  
File Role Description
  Plain text file ImportUserRepositoryInterface.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Builder  
File Role Description
  Plain text file ImportResultFactory.php Class Class source
  Plain text file ImportUserFactory.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Csv  
File Role Description
Files folder imageBuilder (4 files)
Files folder imageData (2 files)
Files folder imageFilter (1 file)
  Plain text file Reader.php Class Class source
  Plain text file ReaderFilterIterator.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Csv  /  Builder  
File Role Description
  Plain text file PathFactory.php Class Class source
  Plain text file ReaderFactory.php Class Class source
  Plain text file ReaderFilterIteratorFactory.php Class Class source
  Plain text file RowFactory.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Csv  /  Data  
File Role Description
  Plain text file Path.php Class Class source
  Plain text file Row.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Csv  /  Filter  
File Role Description
  Plain text file CommentFilter.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Data  
File Role Description
  Plain text file ImportResult.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Exception  
File Role Description
  Plain text file ExceptionInterface.php Class Class source
  Plain text file InvalidArgumentException.php Class Class source
  Plain text file RuntimeException.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Manager  
File Role Description
  Plain text file ImportUserManager.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Repository  
File Role Description
  Plain text file ImportUserRepository.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Resources  
File Role Description
Files folder imageconfig (2 files, 1 directory)

  Files folder image Files  /  src  /  AppBundle  /  Resources  /  config  
File Role Description
Files folder imagedoctrine (1 file)
  Accessible without login Plain text file services.yml Data Auxiliary data
  Accessible without login Plain text file validation.yml Data Auxiliary data

  Files folder image Files  /  src  /  AppBundle  /  Resources  /  config  /  doctrine  
File Role Description
  Accessible without login Plain text file ImportUser.orm.yml Data Auxiliary data

  Files folder image Files  /  src  /  AppBundle  /  Service  
File Role Description
  Plain text file AgeStatistics.php Class Class source
  Plain text file ImportCsvUser.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageAppBundle (1 file, 4 directories)

  Files folder image Files  /  tests  /  AppBundle  
File Role Description
Files folder imageCommand (2 files)
Files folder imagedata (3 files)
Files folder imageModel (1 file, 2 directories)
Files folder imageService (2 files)
  Plain text file BaseTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Command  
File Role Description
  Plain text file UserAgeAverageCommandTest.php Class Class source
  Plain text file UserImportCsvCommandTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  data  
File Role Description
  Accessible without login Plain text file user.full.fields.csv Data Auxiliary data
  Accessible without login Plain text file user.full.with.comments.csv Data Auxiliary data
  Accessible without login Plain text file user.headers.only.csv Data Auxiliary data

  Files folder image Files  /  tests  /  AppBundle  /  Model  
File Role Description
Files folder imageBuilder (1 file)
Files folder imageCsv (1 file, 1 directory)
  Plain text file ObjectManagerTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Model  /  Builder  
File Role Description
  Plain text file ImportUserFactoryTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Model  /  Csv  
File Role Description
Files folder imageFilter (1 file)
  Plain text file ReaderTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Model  /  Csv  /  Filter  
File Role Description
  Plain text file CommentFilterTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Service  
File Role Description
  Plain text file AgeStatisticsTest.php Class Class source
  Plain text file ImportCsvUserTest.php Class Class source

  Files folder image Files  /  var  
File Role Description
  Plain text file SymfonyRequirements.php Class Class source

  Files folder image Files  /  web  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file app.php Example Example script
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file app_dev.php Example Example script
  Accessible without login Plain text file config.php Example Example script
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Plain text file robots.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:108
This week:4
All time:9,165
This week:92Up