<?php

# In der datenbank 'sternwarte' in der Tabelle SoFue 
# zusätzliche Felder anfügen

include '../dbaseconf.php';
 
$newfields[] = array(
         "field" => 'deleted',
         "kind" => boolean,
         "deflt" => false);

$newfields[] = array(
            "field" => 'stattgefunden',
            "kind" => boolean,
            "deflt" => true);

$newfields[] = array(
    "field" => 'verlegt',
    "kind" => datetime,
    "deflt" => null);

$newfields[] = array(
    "field" => 'bezahlt',
    "kind" => "varchar(10)",
    "deflt" => null);

$newfields[] = array(
    "field" => 'owtermin',
    "kind" => datetime,
    "deflt" => null);
    
$newfields[] = array(
    "field" => 'oatermin',
    "kind" => datetime,
    "deflt" => null);

// Einlesen einer Tabelle und rausspeichern auf die Test-Tabelle
function addfields($dbh,$from1) {
    global $newfields;
    
    foreach ($newfields as $f => $inh) {
        $query = 'alter table '. $from1 . ' add ' . $inh["field"] .' '.  $inh["kind"] ;
        if ($inh["nll"] == false) {
            $query = $query . " NOT NULL " ;
        };
        if ($inh["deflt"] != null) {
            $query = $query . ' default ' . $inh["deflt"] ;
        };
        echo 'QUERY: ' . $query . '<br />';
        $rows = mysqli_query($dbh,$query)  or die (mysqli_error($dbh));
    }
//    $query = "alter table " . $from1 . " change termin wtermin ";
//    echo 'QUERY: ' . $query . '<br />';
//   $rows = mysqli_query($dbh,$query)  or die (mysqli_error($dbh));
}

addfields($dbh, 'SoFue');

?>