2

I'm using Symfony 2.7 and Mysql I need to load some real data to database like needed data for countries and cities tables and their relations. What is the right way to do such tasks in Symfony?

A.Alinia
  • 556
  • 5
  • 11
  • no different than PHP I imagine. Don't use PHP loops, use mysql LOAD DATA INFILE. – Drew Nov 29 '15 at 10:13
  • 2
    Possible duplicate of [PHP - Import CSV file to mysql database Using LOAD DATA INFILE](http://stackoverflow.com/questions/18915104/php-import-csv-file-to-mysql-database-using-load-data-infile) – Drew Nov 29 '15 at 10:14
  • 1
    I would suggest you use [Fixtures](http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html). – Turdaliev Nursultan Nov 29 '15 at 10:19
  • @TurdalievNursultan I'd use fixtures in dev environment for testing – A.Alinia Nov 29 '15 at 10:32
  • @Drew (Updated the question) What about the relation between them? – A.Alinia Nov 29 '15 at 10:35
  • That would be represented in the schema and the CSV upload. 1 CSV file per table – Drew Nov 29 '15 at 10:36

1 Answers1

3

For generating test data, use data fixtures. For generating data required in productions, I suggest to use migrations.

Wouter J
  • 39,482
  • 15
  • 97
  • 108