My function stops (nothing in the database) right before Russia.
The reason is probably the different prices (countries before Russia only have 1 price).
(the xml code above is from my xml feed, other countries has been removed etc)
PHP
Last Comment
Ray Paseur
8/22/2022 - Mon
Ray Paseur
You've got your work cut out for you. XML is hierarchical and data bases are relational, so there is rarely a 1:1 mapping. Instead you may need to "normalize" the data base using the structure of the XML. Example: You might have a table of countries and a separate table of prices. These could be joined by a junction table. The "atomic" level is the XML tag that cannot have any elements inside it. So with a quick look at the XML sample here, it seems you would an operator table that relates to a message_profile table that relates to a price table that relates to a country table.
Another alternative would be to ignore normalization and simply flatten all of the XML hierarchy, but that might make it impossible to recover the data in a hierarchically useful way.
kgp43
ASKER
Ye, I should probably look into normalize my database.
However, it does not change the fact that I have an error in my function - I still need to parse that xml feed i think, just insert it differently into my database (if I learn now to normalize my database).
I still can't see any error in my function. It should work with multiple prices ... "foreach ($country->prices->price as $price_level)"
Ray Paseur
I'll make a valid copy of the XML string and see if I can show a way to parse it.
Ul'yanovsk
When I try to put that into my database, then i get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'yanovsk GSM', 'Russia', 'RU', '168', '5.53', '63', '2.07', 'RUB', 'MO', 'FOR DOW' at line 1
Another alternative would be to ignore normalization and simply flatten all of the XML hierarchy, but that might make it impossible to recover the data in a hierarchically useful way.