I have the below code to read in the XML file and to print the query to screen to see what its generating. I have the XML file below that. I'm having problems checking for the for attributes like primary or autonumber, im unable to use if statements and I can't check if there is more then one field to create so that it adds in a colon. Any help much appreciated.
This is what the below ouputs:
Quote:
CREATE TABLE test_table_1 ( id INT(3) )
CREATE TABLE test_table_2 ( id IN(10) test VARCHAR(100) test_2 VARCHAR(15) )
- <?php
-
$file = "queries.xml";
-
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
-
-
foreach ($xml->tables->table as $table) {
-
$query = 'CREATE TABLE '.$table['name'].' ( ';
-
-
foreach ($table->column as $column) {
-
$query .= $column['name'].' '.$column['type'].'('.$column['size'].') ';
-
}
-
$query .= ' )';
-
-
print $query.'<br/>';
-
}
-
?>
- <?xml version="1.0" encoding="UTF-8"?>
-
<structure>
-
<tables>
-
<table name="test_table_1">
-
<column name="id" type="INT" size="3" primary="true" autonumber="true" />
-
</table>
-
<table name="test_table_2">
-
<column name="id" type="IN" size="10" primary="true" autonumber="true" />
-
<column name="test" type="VARCHAR" size="100" />
-
<column name="test_2" type="VARCHAR" size="15" />
-
</table>
-
</tables>
-
</structure>