How to create XML tags from the column names of a mysql database?

4

How do I create XML tags with the column names of a table from a myslq query?

In the code I made I just get the values from each cell in the table, but what I wanted was to automatically create the tags according to each column.

My Current Code

    
asked by anonymous 13.10.2016 / 17:01

2 answers

3

To list the name of your columns in mysql you use the following command

$sql = "desc NomeDaTabela";
$result = @mysql_query($sql);
while($row = @mysql_fetch_array($result)){
    echo $row[0]."<br>";
}
    
13.10.2016 / 17:29
2

You can use information schema to get the column names of your table.

One example you can apply is this :

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
   WHERE TABLE_SCHEMA = 'testes' AND TABLE_NAME = 'testes';
    
13.10.2016 / 17:31