How to Load XML Data into MySQL using PHP ?
In this article, we are going to store data present in XML file into MySQL database using PHP in XAMPP server.
XML: Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The design goals of XML focus on simplicity, generality, and usability across the Internet.
Loading XML file: We will use simplexml_load_file() function to convert the well-formed XML document into the given file to an object.
SimpleXMLElement simplexml_load_file( string $filename, string $class_name = "SimpleXMLElement", int $options = 0, string $ns = "", bool $is_prefix = FALSE )
Steps to Write and Execute code:
- Start XAMPP
- Identify number of attributes in xml file and create table in XAMPP. There are 4 attributes in XML file (input.xml is the file name). These are title, link. description, keywords. The database name is xmldata and table name is xml
1. Save 2 files in one folder in path: xampp/htdocs/gfg
2. Type localhost/gfg/index.php and see the output
Now check the data in xml stored in our database or not