• Coding
  • XML into mySQL using PHP

Hello LebGeeks, is there any PHP script to convet a XML file into mySQL DataBase?

if not, what is the best way to do it?

Thanks in advance
I doubt you'd find a method or a library that works on any kind of XML. It is possible to map a SQL schema to XML, but the other way around is more complicated.

If you have a particular XML in mind, maybe you could show it to us so we'd have a better idea.
I think you'd have more luck looking for an XML schema to SQL schema converter. Luck.
It is possible, though probably not the way you want it and with the lack of information I cannot provide you with additional detail (let alone the fact that I don't deal with PHP).

Nevertheless, Object Relational Mappers normally use an intermediate definition of the "Mapping" between the objects and the corresponding tables which also includes a definition of the relationships and indexes (indeces?). Although the purpose of this mapping is not to generate the underlying schemas, most ORMs provide a way to deduce (thus create) the underlying database. You could probably take a look at Doctrine's schema as an example.

That said, I don't think you should use an ORM at all if your purpose is a one off generation of the database. What you should do, is give us more information of what you're trying to achieve, with examples.
There is no such thing as "converting" XML to SQL (or "MySQL" as you say).
You can write a PHP script to parse XML and extract the data you need and generate SQL queries from that to insert the data in a MySQL database. Or you could probably find libraries to store XML in an SQL db and go forward and back between the two storage formats, but it sounds to me like abusing a relational database.
6 days later
Thanks for your replies guys, I managed to do it easily.

I used two parsing methods DOM and SimpleXML, it's a little bit time consuming but it does the job.

If anyone wants to know how please let me know and I'll paste the code!