Sometimes it can be useful to have a dump of the current database schema. The script below reads the schema from a MySQL database and outputs XML that describes the schema.
At first we connect to a MySQL database and use the SHOW TABLES command to return all the tables in the database. Next, we iterate over each table and return the fields for each table using the SHOW FIELDS command. Finally, we put all of the returned information into XML.
Have a look at the code:
You should note that this code is specific to MySQL database. The commands such as SHOW TABLESand SHOW FIELDS are also available for other databases but are specified slightly differently