adoSchema::ParseSchemaString PHP Method

ParseSchemaString() public method

Call this method to parse a string containing an XML schema (see the DTD for the proper format) and generate the SQL necessary to create the database described by the schema.
See also: ParseSchema()
public ParseSchemaString ( string $xmlstring, boolean $returnSchema = FALSE ) : array
$xmlstring string XML schema string.
$returnSchema boolean Return schema rather than parsing.
return array Array of SQL queries, ready to execute.
    function ParseSchemaString($xmlstring, $returnSchema = FALSE)
    {
        if (!is_string($xmlstring) or empty($xmlstring)) {
            return FALSE;
        }
        // do version detection here
        if ($this->SchemaStringVersion($xmlstring) != $this->schemaVersion) {
            return FALSE;
        }
        if ($returnSchema) {
            return $xmlstring;
        }
        $this->success = 2;
        $xmlParser = $this->create_parser();
        if (!xml_parse($xmlParser, $xmlstring, TRUE)) {
            die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xmlParser)), xml_get_current_line_number($xmlParser)));
        }
        xml_parser_free($xmlParser);
        return $this->sqlArray;
    }

Usage Example

Example #1
0
                    printmsg("ERROR => There was an error creating DB user: "******"1.0"?>
<schema version="0.3">
<sql>
    <query>INSERT INTO domains (id,name,admin_email,default_ttl,refresh,retry,expiry,minimum) VALUES (1,'{$default_domain}','hostmaster', 86400, 86400, 3600, 3600, 3600)</query>
    <query>UPDATE sys_config SET value='{$default_domain}' WHERE name like 'dns_defaultdomain'</query>
</sql>
</schema>
EOL;
                $schema = new adoSchema($db);
                // Build the SQL array from the schema XML file
                $domainsql = $schema->ParseSchemaString($xmldefdomain);
                // Execute the SQL on the database
                if ($schema->ExecuteSchema($domainsql) == 2) {
                    $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created default DNS domain '{$default_domain}'.<br>";
                } else {
                    $status++;
                    $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create default DNS domain '{$default_domain}'.<br><span style='font-size: xx-small;'>" . $db->ErrorMsg() . "</span><br>";
                }
                // Open the database config and write the contents to it.
                if (!($fh = @fopen($dbconffile, 'w'))) {
                    $status++;
                    $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to open config file for writing: '{$dbconffile}'.<br>";
                } else {
                    fwrite($fh, "<?php\n\n\$ona_contexts=" . var_export($ona_contexts, TRUE) . ";\n\n?>");
                    fclose($fh);
                    $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created database connection config file.<br>";
All Usage Examples Of adoSchema::ParseSchemaString