}
$NEW = db_mangle_schema($SCHEMA);
$text = "<?php // this file was automatically generated by the schema precompiler from '{$new_schema}'.\n\n// ====> DO NOT EDIT! <===\n\n";
$text .= "\$SCHEMA =\n" . db_data_to_code($NEW);
$text .= ";\n?>\n";
$outname = "{$BASEDIR}/compiled/{$new_schema_name}";
_writefile($outname, $text);
$outname = "{$BASEDIR}/compiled/schema.php";
_writefile($outname, $text);
echo "done.<br>\n";
$SCHEMA = $NEW;
echo "<br>---------------------------------------------------<br><br>\n";
foreach ($CONFIG["CONNECTIONS"] as $database => $ddef) {
    $DB_NAME = $ddef["BASE"];
    echo "-----> Database '{$database}' name='{$DB_NAME}' <------<br><br>\n";
    $connection = _db_open($database, true, true);
    if (!$connection) {
        die("Cannot connect to database '{$database}' (fix connection and/or sourcecode in config.php<br>\n");
    }
    $query = "";
    if (!$OLD) {
        $query .= "drop database if exists {$DB_NAME};\n";
        $query .= "create database if not exists {$DB_NAME};\n\n";
    }
    $query .= "use {$DB_NAME};\n\n";
    $query .= _db_create_tables($OLD, $NEW, $database, $count);
    if (!$count) {
        echo "// nothing to do with this database -> skipping<br/><br/>\n";
        continue;
    }
    $QUERIES[$database] = $query;
function _db_multiquery(&$env, $write, $query, $cb_list)
{
    global $ERROR;
    $ERROR = "";
    global $debug;
    if (@$debug) {
        echo "multiquery: {$query}<br/>\n";
    }
    $database = $env["DB"];
    $connection = _db_open($database, $write);
    if (!$connection) {
        if ($debug) {
            die("no connection\n");
        }
        return null;
    }
    $call = _db_get_driver($database) . "_multiquery";
    //if($debug) echo "calling '$call'<br>\n";
    $res = $call($env, $connection, $query, $cb_list);
    return $res;
}