A file can be generated using PHP from the database and it can be done by the static or dynamic method in PHP. Static methods can be called directly – without creating an instance of a class. Here we are going to discuss how to create an XML file dynamically.
$result=mysql_query("Select * from Table_name");
$xml = new DOMDocument("1.0");
The next thing we need to do is fetch the elements from the table.
Example: If a table has two elements then it should create two XML elements. For that, we will simply use a while loop inside which there will be mysql_fetch_array function to fetch all the data from the table.
Since the database is connected to a local server it won’t run in your ide but once you have made the database it will work fine. To create the database follow the below mentioned procedure
- Create a database fitness in mysql using local server.
- Then create a table user.
- Then add the columns-uid, uname, email, password, description, role, pic.