Reputation: 167182
I am using PHP and MySQL (with Laravel framework). I need to have a field Location. I have two questions:
I have seen open implementations like the below:
If I use any Self Hosted service, I have to store the whole set of data to the the database. This would be huge since the list is around 15 - 20 MB for just CSV and if I store it in MySQL, it will go more than that and it might be a performance issue.
On the other hand, if I use any Hosted REST API service, this would be tedious job to convert it to our native format and there are issues of migration, like:
And for the second issue, what would be the best way to store the location in the database? Would it be good to store it in plain text? If that's the case, there will be like 100s of records with data like:
New York, United States
New York, United States
New York, United States
New York, United States
New York, United States
New York, United States
London, United Kingdom
London, United Kingdom
London, United Kingdom
How do I tackle these issues? What is the best practise? Thanks in advance.
Upvotes: 0
Views: 120
Reputation: 394
Personally, I would load the information into a SQL database, because of the reasons you provide, preventing problems when the 3rd party service is down or changes.
I would take the CSV file, normalise it, and import it into the database.
Country (id, name);
Region (id, name, country_id);
City (id, name, region_id);
This way you are able to select the country for the city.
SELECT co.name
FROM City c
LEFT JOIN Region r
ON c.region_id = r.id
LEFT JOIN Country co
ON r.country_id = co.id
WHERE city.name = '$city';
Upvotes: 1