function insert()
 {
     $link = connect();
     $this->id = getPrimaryKey("calendar", "CA-");
     $result = mysql_query("insert into calendar values ('" . $this->id . "','" . $this->courseId . "','" . $this->startDate . "','" . $this->endDate . "','" . $this->message_es . "','" . $this->message_en . "','" . $this->typeCourse . "')");
     disconnect($link);
 }
Esempio n. 2
0
 function copy(&$base, $whereFields = "")
 {
     $typ =& $this->getTypeInfo();
     if ($whereFields == "") {
         $whereFields = getPrimaryKey($typ);
     }
     foreach ($whereFields as $attribute) {
         if (isset($base->{$attribute})) {
             $this->{$attribute} = $base->{$attribute};
         } else {
             unset($this->{$attribute});
         }
     }
 }
Esempio n. 3
0
function delete(&$base, $whereFields = "")
{
    global $globQuery;
    if (isset($base->up)) {
        //recursive delete
        // Ha veletlenul a whereFields nem az id, akkor az id-t be kell
        // tolteni, mert az kell a rekurziv delete-ben:
        if (!isset($base->id)) {
            $ret = $base->load($whereFields);
            if ($ret == not_found_in_db) {
                return $ret;
            }
        }
        getChildrenFromDb($base, $children);
        foreach ($children as $child) {
            $child->delete($whereFields);
        }
    }
    $typ =& $base->getTypeInfo();
    $table = $base->get_table();
    $query = "DELETE FROM @{$table}";
    $sqlParams = array();
    $whereExists = FALSE;
    if ($whereFields == "") {
        $whereFields = getPrimaryKey($typ);
    }
    if ($whereFields) {
        $firstField = TRUE;
        foreach ($whereFields as $key) {
            if (isset($base->{$key})) {
                $sqlParams[] = $key;
                $sqlParams[] = $base->{$key};
                if ($firstField) {
                    $query .= " WHERE `param`=#param#";
                    $firstField = FALSE;
                    $whereExists = TRUE;
                } else {
                    $query .= " AND `param`=#param#";
                }
            }
        }
    }
    array_unshift($sqlParams, $query);
    $query = $sqlParams;
    $globQuery = $query;
    $hasMany = new HasManyAttrs($base);
    $hasMany->delete();
    if ($whereExists) {
        executeQuery($query);
    } else {
        trigger_error("Delete without WHERE: " . print_r($query, TRUE), E_USER_ERROR);
    }
    return ok;
}
function handleCreateTable(&$schema, &$input, &$line)
{
    if (preg_match('/^CREATE\\ TABLE\\ ([a-z]*\\.)?([a-z_]+)$/', $line, $match) == 1) {
        $tabName = $match[2];
        // eat (
        getNextLine($input);
        $lastcolumn = false;
        while ($line = getNextLine($input)) {
            $comment = false;
            while ($commentLine = getComment($line)) {
                $comment = $comment . "\n" . $commentLine;
                $line = getNextLine($input);
            }
            $column = getColumnName($line);
            if ($column) {
                $lastcolumn = $column;
            }
            if (!isset($schema[$tabName]['fields'][$lastcolumn])) {
                $schema[$tabName]['fields'][$lastcolumn] = array('description' => "No description for column {$lastcolumn} available, please fix");
            }
            if ($comment) {
                $schema[$tabName]['fields'][$lastcolumn]['description'] = $comment;
            }
            if (getColumnType($schema[$tabName], $lastcolumn, $line)) {
                continue;
            }
            if (preg_match('/^\\) WITHOUT OIDS;/', $line)) {
                continue;
            }
            if ($uniqueconstraints = getUniqueConstraints($line)) {
                $keyname = $uniqueconstraints['name'];
                $schema[$tabName]['unique keys'][$keyname] = $uniqueconstraints['keys'];
                continue;
            }
            if ($primaryKey = getPrimaryKey($line)) {
                $schema[$tabName]['primary key'] = $primaryKey;
                continue;
            }
            fwrite(STDERR, "Unknown statements within CREATE TABLE: {$line}\n");
        }
        return true;
    }
    return false;
}
Esempio n. 5
0
function getTable($tableXML, &$database, &$tables)
{
    global $classNames;
    global $build_version;
    $name = trim((string) $tableXML->name);
    $klass = trim((string) $tableXML->class);
    $base = value('base', $tableXML) . '/DAO/';
    $pre = str_replace('/', '_', $base);
    $classNames[$name] = $pre . $klass;
    $localizable = false;
    foreach ($tableXML->field as $fieldXML) {
        if ($fieldXML->localizable) {
            $localizable = true;
            break;
        }
    }
    $table = array('name' => $name, 'base' => $base, 'fileName' => $klass . '.php', 'objectName' => $klass, 'labelName' => substr($name, 8), 'className' => $classNames[$name], 'attributes_simple' => trim($database['tableAttributes_simple']), 'attributes_modern' => trim($database['tableAttributes_modern']), 'comment' => value('comment', $tableXML), 'localizable' => $localizable, 'log' => value('log', $tableXML, 'false'));
    $config =& CRM_Core_Config::singleton(false);
    $fields = array();
    foreach ($tableXML->field as $fieldXML) {
        if (value('drop', $fieldXML, 0) > 0 and value('drop', $fieldXML, 0) <= $build_version) {
            continue;
        }
        // check if hrd field and hrd is enabled to include
        if (value('hrd', $fieldXML, 0) == 1 && !$config->civiHRD) {
            continue;
        }
        if (value('add', $fieldXML, 0) <= $build_version) {
            getField($fieldXML, $fields);
        }
    }
    $table['fields'] =& $fields;
    // print_r($table['fields' ]);
    //Anil
    $table['hasEnum'] = false;
    foreach ($table['fields'] as $field) {
        if ($field['crmType'] == 'CRM_Utils_Type::T_ENUM') {
            $table['hasEnum'] = true;
            break;
        }
    }
    if (value('primaryKey', $tableXML)) {
        getPrimaryKey($tableXML->primaryKey, $fields, $table);
    }
    $config =& CRM_Core_Config::singleton(false);
    if (value('index', $tableXML)) {
        $index = array();
        foreach ($tableXML->index as $indexXML) {
            if (value('drop', $indexXML, 0) > 0 and value('drop', $indexXML, 0) <= $build_version) {
                continue;
            }
            // check if hrd field and hrd is enabled to include
            if (value('hrd', $fieldXML, 0) == 1 && !$config->civiHRD) {
                continue;
            }
            getIndex($indexXML, $fields, $index);
        }
        $table['index'] =& $index;
    }
    if (value('foreignKey', $tableXML)) {
        $foreign = array();
        foreach ($tableXML->foreignKey as $foreignXML) {
            // print_r($foreignXML);
            if (value('drop', $foreignXML, 0) > 0 and value('drop', $foreignXML, 0) <= $build_version) {
                continue;
            }
            if (value('add', $foreignXML, 0) <= $build_version) {
                getForeignKey($foreignXML, $fields, $foreign, $name);
            }
        }
        $table['foreignKey'] =& $foreign;
    }
    $tables[$name] =& $table;
    return;
}
function submit($mysqli, $xml, $XmlVersion)
{
    /*
        query_server($mysqli, "TRUNCATE TABLE `DVDAUDIOSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDAUDIOSTREAMEX`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDSUBPICSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVIDEOSTREAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDFILE`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPTTVMG`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPTTVTS`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDUNIT`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDCELL`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPROGRAM`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDPGC`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVTS`;");
        query_server($mysqli, "TRUNCATE TABLE `DVDVMGM`;");
    */
    // Start a transaction
    query_server($mysqli, "START TRANSACTION;");
    foreach ($xml->DVD as $tagDVDVMGM) {
        $attributes = $tagDVDVMGM->attributes();
        $Hash = value_or_null($attributes["Hash"]);
        $SubmitterIP = value_or_null($_SERVER['REMOTE_ADDR']);
        $Album = value_or_null($tagDVDVMGM->Album);
        $OriginalAlbum = value_or_null($tagDVDVMGM->OriginalAlbum);
        $AlbumArtist = value_or_null($tagDVDVMGM->AlbumArtist);
        $Genre = value_or_null($tagDVDVMGM->Genre);
        $Cast = value_or_null($tagDVDVMGM->Cast);
        $Crew = value_or_null($tagDVDVMGM->Crew);
        $Director = value_or_null($tagDVDVMGM->Director);
        $Screenplay = value_or_null($tagDVDVMGM->Screenplay);
        $Producer = value_or_null($tagDVDVMGM->Producer);
        $Editing = value_or_null($tagDVDVMGM->Editing);
        $Cinematography = value_or_null($tagDVDVMGM->Cinematography);
        $Country = value_or_null($tagDVDVMGM->Country);
        $OriginalLanguage = value_or_null($tagDVDVMGM->OriginalLanguage);
        $ReleaseDate = date_or_null($tagDVDVMGM->ReleaseDate);
        $SpecialFeatures = value_or_null($tagDVDVMGM->SpecialFeatures);
        $EAN_UPC = value_or_null($tagDVDVMGM->EAN_UPC);
        $Storyline = value_or_null($tagDVDVMGM->Storyline);
        $Submitter = value_or_null($tagDVDVMGM->Submitter);
        $Client = value_or_null($tagDVDVMGM->Client);
        $Remarks = value_or_null($tagDVDVMGM->Remarks);
        $Keywords = value_or_null($tagDVDVMGM->Keywords);
        $RegionProhibited1 = value_or_null($attributes["RegionProhibited1"]);
        $RegionProhibited2 = value_or_null($attributes["RegionProhibited2"]);
        $RegionProhibited3 = value_or_null($attributes["RegionProhibited3"]);
        $RegionProhibited4 = value_or_null($attributes["RegionProhibited4"]);
        $RegionProhibited5 = value_or_null($attributes["RegionProhibited5"]);
        $RegionProhibited6 = value_or_null($attributes["RegionProhibited6"]);
        $RegionProhibited7 = value_or_null($attributes["RegionProhibited7"]);
        $RegionProhibited8 = value_or_null($attributes["RegionProhibited8"]);
        $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
        $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
        $NumberOfVolumes = value_or_null($attributes["NumberOfVolumes"]);
        $VolumeNumber = value_or_null($attributes["VolumeNumber"]);
        $SideID = value_or_null($attributes["SideID"]);
        if ($Submitter == DEFSUBMITTER) {
            $Submitter = null;
        }
        // Check if dataset exists
        $found = FALSE;
        /* Feature #884: deactivated unstable feature for rev 0.40
        
                $strSQL = "SELECT `idDVDVMGM`, `RowLastChanged`, `RowCreationDate`, `Submitter`, `SubmitterIP` FROM `DVDVMGM` ".
                            "WHERE `Hash` = '" . $Hash . "' AND `Active` = 1 " .
                            "ORDER BY `Revision` DESC;";
        
                $rsDVDVMGM = query_server($mysqli, $strSQL);
        
                if (is_array($Cols = $rsDVDVMGM->fetch_row()))
                {
                    $idDVDVMGM          = $Cols[0];
                    $RowLastChanged     = $Cols[1];
                    $RowCreationDate    = $Cols[2];
                    $LastSubmitter      = $Cols[3];
                    $LastSubmitterIP    = $Cols[4];
        
                    // TODO: maybe check submission time
                    if ($Submitter == $LastSubmitter && $SubmitterIP == $LastSubmitterIP)
                    {
                        $found = TRUE;
                    }
                }
        
                $rsDVDVMGM->close();
        */
        if (!$found) {
            // Not found: insert new
            $strSQL = "INSERT INTO `DVDVMGM` (`Hash`, `Album`, `AlbumArtist`, `Genre`, `Cast`, `Crew`, `Director`, `Country`, `ReleaseDate`, `SpecialFeatures`, `EAN_UPC`, `Storyline`, `Remarks`, `Submitter`, `SubmitterIP`, `Client`, `Keywords`, `RegionProhibited1`, `RegionProhibited2`, `RegionProhibited3`, `RegionProhibited4`, `RegionProhibited5`, `RegionProhibited6`, `RegionProhibited7`, `RegionProhibited8`, `VersionNumberMajor`, `VersionNumberMinor`, `NumberOfVolumes`, `VolumeNumber`, `SideID`, `OriginalAlbum`, `Screenplay`, `Producer`, `Editing`, `Cinematography`, `OriginalLanguage`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
            $stmt = $mysqli->prepare($strSQL);
            if (!$stmt) {
                $ResponseText = "Error preparing insert statement for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->bind_param("sssssssssssssssssiiiiiiiiiiiiissssss", $Hash, $Album, $AlbumArtist, $Genre, $Cast, $Crew, $Director, $Country, $ReleaseDate, $SpecialFeatures, $EAN_UPC, $Storyline, $Remarks, $Submitter, $SubmitterIP, $Client, $Keywords, $RegionProhibited1, $RegionProhibited2, $RegionProhibited3, $RegionProhibited4, $RegionProhibited5, $RegionProhibited6, $RegionProhibited7, $RegionProhibited8, $VersionNumberMajor, $VersionNumberMinor, $NumberOfVolumes, $VolumeNumber, $SideID, $OriginalAlbum, $Screenplay, $Producer, $Editing, $Cinematography, $OriginalLanguage)) {
                $ResponseText = "Error binding parameters for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->execute()) {
                $ResponseText = "Error executing statement on DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            $idDVDVMGM = $mysqli->insert_id;
            $stmt->close();
            $stmt = null;
            // Physical structure
            $tagPhysical = $tagDVDVMGM->physical;
            foreach ($tagPhysical->DVDVTS as $tagDVDVTS) {
                // Insert DVDVTS (Video Title Set)
                $attributes = $tagDVDVTS->attributes();
                $TitleSetNo = $attributes["TitleSetNo"];
                $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
                $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
                $strSQL = "INSERT INTO `DVDVTS` (`DVDVMGMKey`, `TitleSetNo`, `VersionNumberMajor`, `VersionNumberMinor`) VALUES (?, ?, ?, ?);";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iiii", $idDVDVMGM, $TitleSetNo, $VersionNumberMajor, $VersionNumberMinor)) {
                    $ResponseText = "Error binding parameters for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $idDVDVTS = $mysqli->insert_id;
                $stmt->close();
                foreach ($tagDVDVTS->DVDPGC as $tagDVDPGC) {
                    // Insert DVDPGC (Program Chain)
                    $attributes = $tagDVDPGC->attributes();
                    $ProgramChainNo = value_or_null($attributes["Number"]);
                    $EntryPGC = value_or_null($attributes["EntryPGC"]);
                    $strSQL = "INSERT INTO `DVDPGC` (`DVDVTSKey`, `ProgramChainNo`, `EntryPGC`) VALUES (?, ?, ?);";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("iii", $idDVDVTS, $ProgramChainNo, $EntryPGC)) {
                        $ResponseText = "Error binding parameters for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    $idDVDPGC = $mysqli->insert_id;
                    $stmt->close();
                    foreach ($tagDVDPGC->DVDPROGRAM as $tagDVDPROGRAM) {
                        // Insert DVDPGC (Program)
                        $attributes = $tagDVDPROGRAM->attributes();
                        $ProgramNo = value_or_null($attributes["Number"]);
                        $strSQL = "INSERT INTO `DVDPROGRAM` (`DVDPGCKey`, `ProgramNo`) VALUES (?, ?);";
                        $stmt = $mysqli->prepare($strSQL);
                        if (!$stmt) {
                            $ResponseText = "Error preparing insert statement for chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        if (!$stmt->bind_param("ii", $idDVDPGC, $ProgramNo)) {
                            $ResponseText = "Error binding parameters for chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            $stmt->close();
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        if (!$stmt->execute()) {
                            $ResponseText = "Error executing statement on chapter table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                            $stmt->close();
                            throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                        }
                        $idDVDPROGRAM = $mysqli->insert_id;
                        $stmt->close();
                        foreach ($tagDVDPROGRAM->DVDCELL as $tagDVDCELL) {
                            // Insert DVDCELL (Cell)
                            $attributes = $tagDVDCELL->attributes();
                            $CellNo = value_or_null($attributes["Number"]);
                            $CellType = value_or_null($attributes["CellType"]);
                            $BlockType = value_or_null($attributes["BlockType"]);
                            $SeamlessMultiplex = value_or_null($attributes["SeamlessMultiplex"]);
                            $Interleaved = value_or_null($attributes["Interleaved"]);
                            $SCRdiscontinuity = value_or_null($attributes["SCRdiscontinuity"]);
                            $SeamlessAngleLinkedInDSI = value_or_null($attributes["SeamlessAngleLinkedInDSI"]);
                            $VOBStillMode = value_or_null($attributes["VOBStillMode"]);
                            $StopsTrickPlay = value_or_null($attributes["StopsTrickPlay"]);
                            $CellStillTime = value_or_null($attributes["CellStillTime"]);
                            $CellCommand = value_or_null($attributes["CellCommand"]);
                            $PlayTime = value_or_null($attributes["PlayTime"]);
                            $FrameRate = value_or_null($attributes["FrameRate"]);
                            $FirstVOBUStartSector = value_or_null($attributes["FirstVOBUStartSector"]);
                            $FirstILVUEndSector = value_or_null($attributes["FirstILVUEndSector"]);
                            $LastVOBUStartSector = value_or_null($attributes["LastVOBUStartSector"]);
                            $LastVOBUEndSector = value_or_null($attributes["LastVOBUEndSector"]);
                            $VOBidn = value_or_null($attributes["VOBidn"]);
                            $CELLidn = value_or_null($attributes["CELLidn"]);
                            $NumberOfVOBIds = value_or_null($attributes["NumberOfVOBIds"]);
                            $strSQL = "INSERT INTO `DVDCELL` (`DVDPROGRAMKey`, `CellNo`, `CellType`, `BlockType`, `SeamlessMultiplex`, `Interleaved`, `SCRdiscontinuity`, `SeamlessAngleLinkedInDSI`, `VOBStillMode`, `StopsTrickPlay`, `CellStillTime`, `CellCommand`, `PlayTime`, `FrameRate`, `FirstVOBUStartSector`, `FirstILVUEndSector`, `LastVOBUStartSector`, `LastVOBUEndSector`, `VOBidn`, `CELLidn`, `NumberOfVOBIds`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                            $stmt = $mysqli->prepare($strSQL);
                            if (!$stmt) {
                                $ResponseText = "Error preparing insert statement for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->bind_param("iissiiiiiiiiiiiiiiiii", $idDVDPROGRAM, $CellNo, $CellType, $BlockType, $SeamlessMultiplex, $Interleaved, $SCRdiscontinuity, $SeamlessAngleLinkedInDSI, $VOBStillMode, $StopsTrickPlay, $CellStillTime, $CellCommand, $PlayTime, $FrameRate, $FirstVOBUStartSector, $FirstILVUEndSector, $LastVOBUStartSector, $LastVOBUEndSector, $VOBidn, $CELLidn, $NumberOfVOBIds)) {
                                $ResponseText = "Error binding parameters for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->execute()) {
                                $ResponseText = "Error executing statement on DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            $idDVDCELL = $mysqli->insert_id;
                            $stmt->close();
                            foreach ($tagDVDCELL->DVDUNIT as $tagDVDUNIT) {
                                // Insert DVDUNIT (Unit)
                                $attributes = $tagDVDUNIT->attributes();
                                $UnitNo = value_or_null($attributes["Number"]);
                                $StartSector = value_or_null($attributes["StartSector"]);
                                $EndSector = value_or_null($attributes["EndSector"]);
                                $strSQL = "INSERT INTO `DVDUNIT` (`DVDCELLKey`, `UnitNo`, `StartSector`, `EndSector`) VALUES (?, ?, ?, ?);";
                                $stmt = $mysqli->prepare($strSQL);
                                if (!$stmt) {
                                    $ResponseText = "Error preparing insert statement for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->bind_param("iiii", $idDVDCELL, $UnitNo, $StartSector, $EndSector)) {
                                    $ResponseText = "Error binding parameters for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->execute()) {
                                    $ResponseText = "Error executing statement on DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                //$idDVDUNIT = $mysqli->insert_id;
                                $stmt->close();
                            }
                        }
                    }
                }
                // DVDVIDEOSTREAM
                foreach ($tagDVDVTS->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                    addVideoStream($mysqli, $tagDVDVIDEOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAM
                foreach ($tagDVDVTS->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                    addAudioStream($mysqli, $tagDVDAUDIOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAMEX
                foreach ($tagDVDVTS->DVDAUDIOSTREAMEX as $audiostreamExTag) {
                    addAudioStreamEx($mysqli, $audiostreamExTag, $idDVDVTS);
                }
                // DVDSUBPICSTREAM
                foreach ($tagDVDVTS->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                    addSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, null, $idDVDVTS);
                }
                // Fileset
                foreach ($tagDVDVTS->DVDFILE as $tagDVDFILE) {
                    addFileset($mysqli, $tagDVDFILE, null, $idDVDVTS);
                }
            }
            // Virtual structure
            $tagVirtual = $tagDVDVMGM->virtual;
            foreach ($tagVirtual->DVDPTTVMG as $tagDVDPTTVMG) {
                // Insert DVDPTTVMG (Video Title Set)
                $attributes = $tagDVDPTTVMG->attributes();
                $Title = value_or_null($tagDVDPTTVMG->Title);
                $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                $PlaybackType = value_or_null($attributes["PlaybackType"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $ParentalMgmMaskVMG = value_or_null($attributes["ParentalMgmMaskVMG"]);
                $ParentalMgmMaskVTS = value_or_null($attributes["ParentalMgmMaskVTS"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $VideoTitleSetNo = value_or_null($attributes["VideoTitleSetNo"]);
                $TitleNo = value_or_null($attributes["TitleNo"]);
                $strSQL = "INSERT INTO `DVDPTTVMG` (`DVDVMGMKey`, `TitleSetNo`, `Title`, `PlaybackType`, `NumberOfVideoAngles`, `ParentalMgmMaskVMG`, `ParentalMgmMaskVTS`, `VideoTitleSetNo`, `TitleNo`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iisiiiiii", $idDVDVMGM, $TitleSetNo, $Title, $PlaybackType, $NumberOfVideoAngles, $ParentalMgmMaskVMG, $ParentalMgmMaskVTS, $VideoTitleSetNo, $TitleNo)) {
                    $ResponseText = "Error binding parameters for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $idDVDPTTVMG = $mysqli->insert_id;
                $stmt->close();
                foreach ($tagDVDPTTVMG->DVDPTTVTS as $tagDVDPTTVTS) {
                    // Insert DVDPTTVTS (Chapter)
                    $attributes = $tagDVDPTTVTS->attributes();
                    $Title = value_or_null($tagDVDPTTVTS->Title);
                    $Artist = value_or_null($tagDVDPTTVTS->Artist);
                    $ProgramChainNo = value_or_null($attributes["ProgramChainNo"]);
                    $ProgramNo = value_or_null($attributes["ProgramNo"]);
                    $PttTitleSetNo = value_or_null($attributes["PttTitleSetNo"]);
                    $PttChapterNo = value_or_null($attributes["Number"]);
                    $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                    $strSQL = "INSERT INTO `DVDPTTVTS` (`DVDPTTVMGKey`, `Artist`, `Title`, `ProgramChainNo`, `ProgramNo`, `PttTitleSetNo`, `PttChapterNo`, `TitleSetNo`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("issiiiii", $idDVDPTTVMG, $Artist, $Title, $ProgramChainNo, $ProgramNo, $PttTitleSetNo, $PttChapterNo, $TitleSetNo)) {
                        $ResponseText = "Error binding parameters for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    //$idDVDPTTVTS = $mysqli->insert_id;
                    $stmt->close();
                }
            }
            // DVDVIDEOSTREAM
            foreach ($tagDVDVMGM->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                addVideoStream($mysqli, $tagDVDVIDEOSTREAM, $idDVDVMGM, null);
            }
            // DVDAUDIOSTREAM
            foreach ($tagDVDVMGM->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                addAudioStream($mysqli, $tagDVDAUDIOSTREAM, $idDVDVMGM, null);
            }
            // DVDSUBPICSTREAM
            foreach ($tagDVDVMGM->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                addSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, $idDVDVMGM, null);
            }
            // Fileset
            foreach ($tagDVDVMGM->DVDFILE as $tagDVDFILE) {
                addFileset($mysqli, $tagDVDFILE, $idDVDVMGM, null);
            }
        } else {
            // Found: do an update
            $strSQL = "UPDATE `DVDVMGM` SET `Album` = ?, `AlbumArtist` = ?, `Genre` = ?, `Cast` = ?, `Crew` = ?, `Director` = ?, `Country` = ?, `ReleaseDate` = ?, `SpecialFeatures` = ?, `EAN_UPC` = ?, `Storyline` = ?, `Remarks` = ?, `Submitter` = ?, `SubmitterIP` = ?, `Client` = ?, `Keywords` = ?, `RegionProhibited1` = ?, `RegionProhibited2` = ?, `RegionProhibited3` = ?, `RegionProhibited4` = ?, `RegionProhibited5` = ?, `RegionProhibited6` = ?, `RegionProhibited7` = ?, `RegionProhibited8` = ?, `VersionNumberMajor` = ?, `VersionNumberMinor` = ?, `NumberOfVolumes` = ?, `VolumeNumber` = ?, `OriginalAlbum` = ?, `Screenplay` = ?, `Producer` = ?, `Editing` = ?, `Cinematography` = ?, `OriginalLanguage` = ?, `SideID` = ? WHERE `idDVDVMGM` = ?;";
            $stmt = $mysqli->prepare($strSQL);
            if (!$stmt) {
                $ResponseText = "Error preparing update statement for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->bind_param("ssssssssssssssssiiiiiiiiiiiissssssii", $Album, $AlbumArtist, $Genre, $Cast, $Crew, $Director, $Country, $ReleaseDate, $SpecialFeatures, $EAN_UPC, $Storyline, $Remarks, $Submitter, $SubmitterIP, $Client, $Keywords, $RegionProhibited1, $RegionProhibited2, $RegionProhibited3, $RegionProhibited4, $RegionProhibited5, $RegionProhibited6, $RegionProhibited7, $RegionProhibited8, $VersionNumberMajor, $VersionNumberMinor, $NumberOfVolumes, $VolumeNumber, $OriginalAlbum, $Screenplay, $Producer, $Editing, $Cinematography, $OriginalLanguage, $SideID, $idDVDVMGM)) {
                $ResponseText = "Error binding parameters for DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            if (!$stmt->execute()) {
                $ResponseText = "Error executing statement on DVDVMGM table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                $stmt->close();
                $stmt = null;
                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
            }
            $stmt->close();
            $stmt = null;
            // Physical structure
            $tagPhysical = $tagDVDVMGM->physical;
            foreach ($tagPhysical->DVDVTS as $tagDVDVTS) {
                // Update DVDVTS (Video Title Set)
                $attributes = $tagDVDVTS->attributes();
                $TitleSetNo = $attributes["TitleSetNo"];
                $VersionNumberMajor = value_or_null($attributes["VersionNumberMajor"]);
                $VersionNumberMinor = value_or_null($attributes["VersionNumberMinor"]);
                $idDVDVTS = getPrimaryKey($mysqli, "DVDVTS", "idDVDVTS", "`DVDVMGMKey` = {$idDVDVMGM} AND `TitleSetNo` = {$TitleSetNo}");
                $strSQL = "UPDATE `DVDVTS` SET `TitleSetNo` = ?, `VersionNumberMajor` = ?, `VersionNumberMinor` = ? WHERE `idDVDVTS` = ?;";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing update statement for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("iiii", $TitleSetNo, $VersionNumberMajor, $VersionNumberMinor, $idDVDVTS)) {
                    $ResponseText = "Error binding parameters for DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $stmt->close();
                foreach ($tagDVDVTS->DVDPGC as $tagDVDPGC) {
                    // Update DVDPGC (Program Chain)
                    $attributes = $tagDVDPGC->attributes();
                    $ProgramChainNo = value_or_null($attributes["Number"]);
                    $EntryPGC = value_or_null($attributes["EntryPGC"]);
                    $idDVDPGC = getPrimaryKey($mysqli, "DVDPGC", "idDVDPGC", "`DVDVTSKey` = {$idDVDVTS} AND `ProgramChainNo` = {$ProgramChainNo}");
                    $strSQL = "UPDATE `DVDPGC` SET `EntryPGC` = ? WHERE `idDVDPGC` = ?;";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("ii", $EntryPGC, $idDVDPGC)) {
                        $ResponseText = "Error binding parameters for DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPGC table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    $stmt->close();
                    foreach ($tagDVDPGC->DVDPROGRAM as $tagDVDPROGRAM) {
                        // Update DVDPGC (Program)
                        $attributes = $tagDVDPROGRAM->attributes();
                        $ProgramNo = value_or_null($attributes["Number"]);
                        // Nothing to update...
                        $idDVDPROGRAM = getPrimaryKey($mysqli, "DVDPROGRAM", "idDVDPROGRAM", "`DVDPGCKey` = {$idDVDPGC} AND `ProgramNo` = {$ProgramNo}");
                        foreach ($tagDVDPROGRAM->DVDCELL as $tagDVDCELL) {
                            // Update DVDCELL (Cell)
                            $attributes = $tagDVDCELL->attributes();
                            $CellNo = value_or_null($attributes["Number"]);
                            $CellType = value_or_null($attributes["CellType"]);
                            $BlockType = value_or_null($attributes["BlockType"]);
                            $SeamlessMultiplex = value_or_null($attributes["SeamlessMultiplex"]);
                            $Interleaved = value_or_null($attributes["Interleaved"]);
                            $SCRdiscontinuity = value_or_null($attributes["SCRdiscontinuity"]);
                            $SeamlessAngleLinkedInDSI = value_or_null($attributes["SeamlessAngleLinkedInDSI"]);
                            $VOBStillMode = value_or_null($attributes["VOBStillMode"]);
                            $StopsTrickPlay = value_or_null($attributes["StopsTrickPlay"]);
                            $CellStillTime = value_or_null($attributes["CellStillTime"]);
                            $CellCommand = value_or_null($attributes["CellCommand"]);
                            $PlayTime = value_or_null($attributes["PlayTime"]);
                            $FrameRate = value_or_null($attributes["FrameRate"]);
                            $FirstVOBUStartSector = value_or_null($attributes["FirstVOBUStartSector"]);
                            $FirstILVUEndSector = value_or_null($attributes["FirstILVUEndSector"]);
                            $LastVOBUStartSector = value_or_null($attributes["LastVOBUStartSector"]);
                            $LastVOBUEndSector = value_or_null($attributes["LastVOBUEndSector"]);
                            $VOBidn = value_or_null($attributes["VOBidn"]);
                            $CELLidn = value_or_null($attributes["CELLidn"]);
                            $NumberOfVOBIds = value_or_null($attributes["NumberOfVOBIds"]);
                            $idDVDCELL = getPrimaryKey($mysqli, "DVDCELL", "idDVDCELL", "`DVDPROGRAMKey` = {$idDVDPROGRAM} AND `CellNo` = {$CellNo}");
                            $strSQL = "UPDATE `DVDCELL` SET `CellType` = ?, `BlockType` = ?, `SeamlessMultiplex` = ?, `Interleaved` = ?, `SCRdiscontinuity` = ?, `SeamlessAngleLinkedInDSI` = ?, `VOBStillMode` = ?, `StopsTrickPlay` = ?, `CellStillTime` = ?, `CellCommand` = ?, `PlayTime` = ?, `FrameRate` = ?, `FirstVOBUStartSector` = ?, `FirstILVUEndSector` = ?, `LastVOBUStartSector` = ?, `LastVOBUEndSector` = ?, `VOBidn` = ?, `CELLidn` = ?, `NumberOfVOBIds` = ? WHERE `idDVDCELL` = ?;";
                            $stmt = $mysqli->prepare($strSQL);
                            if (!$stmt) {
                                $ResponseText = "Error preparing insert statement for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->bind_param("ssiiiiiiiiiiiiiiiiii", $CellType, $BlockType, $SeamlessMultiplex, $Interleaved, $SCRdiscontinuity, $SeamlessAngleLinkedInDSI, $VOBStillMode, $StopsTrickPlay, $CellStillTime, $CellCommand, $PlayTime, $FrameRate, $FirstVOBUStartSector, $FirstILVUEndSector, $LastVOBUStartSector, $LastVOBUEndSector, $VOBidn, $CELLidn, $NumberOfVOBIds, $idDVDCELL)) {
                                $ResponseText = "Error binding parameters for DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            if (!$stmt->execute()) {
                                $ResponseText = "Error executing statement on DVDCELL table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                $stmt->close();
                                throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                            }
                            $stmt->close();
                            foreach ($tagDVDCELL->DVDUNIT as $tagDVDUNIT) {
                                // Update DVDUNIT (Unit)
                                $attributes = $tagDVDUNIT->attributes();
                                $UnitNo = value_or_null($attributes["Number"]);
                                $StartSector = value_or_null($attributes["StartSector"]);
                                $EndSector = value_or_null($attributes["EndSector"]);
                                $strSQL = "UPDATE `DVDUNIT` SET `StartSector` = ?, `EndSector` = ? WHERE `DVDCELLKey` = ? AND `UnitNo` = ?;";
                                $stmt = $mysqli->prepare($strSQL);
                                if (!$stmt) {
                                    $ResponseText = "Error preparing insert statement for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->bind_param("iiii", $StartSector, $EndSector, $idDVDCELL, $UnitNo)) {
                                    $ResponseText = "Error binding parameters for DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                if (!$stmt->execute()) {
                                    $ResponseText = "Error executing statement on DVDUNIT table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                                    $stmt->close();
                                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                                }
                                //$idDVDUNIT = $mysqli->insert_id;
                                $stmt->close();
                            }
                        }
                    }
                }
                // DVDVIDEOSTREAM
                foreach ($tagDVDVTS->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                    updateVideoStream($mysqli, $tagDVDVIDEOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAM
                foreach ($tagDVDVTS->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                    updateAudioStream($mysqli, $tagDVDAUDIOSTREAM, null, $idDVDVTS);
                }
                // DVDAUDIOSTREAMEX
                foreach ($tagDVDVTS->DVDAUDIOSTREAMEX as $audiostreamExTag) {
                    updateAudioStreamEx($mysqli, $audiostreamExTag, $idDVDVTS);
                }
                // DVDSUBPICSTREAM
                foreach ($tagDVDVTS->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                    updateSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, null, $idDVDVTS);
                }
                // Fileset
                foreach ($tagDVDVTS->DVDFILE as $tagDVDFILE) {
                    updateFileset($mysqli, $tagDVDFILE, null, $idDVDVTS);
                }
            }
            // Virtual structure
            $tagVirtual = $tagDVDVMGM->virtual;
            foreach ($tagVirtual->DVDPTTVMG as $tagDVDPTTVMG) {
                // Update DVDPTTVMG (Video Title Set)
                $attributes = $tagDVDPTTVMG->attributes();
                $Title = value_or_null($tagDVDPTTVMG->Title);
                $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                $PlaybackType = value_or_null($attributes["PlaybackType"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $ParentalMgmMaskVMG = value_or_null($attributes["ParentalMgmMaskVMG"]);
                $ParentalMgmMaskVTS = value_or_null($attributes["ParentalMgmMaskVTS"]);
                $NumberOfVideoAngles = value_or_null($attributes["NumberOfVideoAngles"]);
                $VideoTitleSetNo = value_or_null($attributes["VideoTitleSetNo"]);
                $TitleNo = value_or_null($attributes["TitleNo"]);
                $idDVDPTTVMG = getPrimaryKey($mysqli, "DVDPTTVMG", "idDVDPTTVMG", "`DVDVMGMKey` = {$idDVDVMGM} AND `TitleSetNo` = {$TitleSetNo}");
                $strSQL = "UPDATE `DVDPTTVMG` SET `Title` = ?, `PlaybackType` = ?, `NumberOfVideoAngles` = ?, `ParentalMgmMaskVMG` = ?, `ParentalMgmMaskVTS` = ?, `VideoTitleSetNo` = ?, `TitleNo` = ? WHERE `idDVDPTTVMG` = ?;";
                $stmt = $mysqli->prepare($strSQL);
                if (!$stmt) {
                    $ResponseText = "Error preparing insert statement for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->bind_param("siiiiiii", $Title, $PlaybackType, $NumberOfVideoAngles, $ParentalMgmMaskVMG, $ParentalMgmMaskVTS, $VideoTitleSetNo, $TitleNo, $idDVDPTTVMG)) {
                    $ResponseText = "Error binding parameters for DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                if (!$stmt->execute()) {
                    $ResponseText = "Error executing statement on DVDPTTVMG table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                    $stmt->close();
                    throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                }
                $stmt->close();
                foreach ($tagDVDPTTVMG->DVDPTTVTS as $tagDVDPTTVTS) {
                    // Update DVDPTTVTS (Chapter)
                    $attributes = $tagDVDPTTVTS->attributes();
                    $Title = value_or_null($tagDVDPTTVTS->Title);
                    $Artist = value_or_null($tagDVDPTTVTS->Artist);
                    $ProgramChainNo = value_or_null($attributes["ProgramChainNo"]);
                    $ProgramNo = value_or_null($attributes["ProgramNo"]);
                    $PttTitleSetNo = value_or_null($attributes["PttTitleSetNo"]);
                    $PttChapterNo = value_or_null($attributes["Number"]);
                    $TitleSetNo = value_or_null($attributes["TitleSetNo"]);
                    $strSQL = "UPDATE `DVDPTTVTS` SET `Artist` = ?, `Title` = ?, `ProgramChainNo` = ?, `ProgramNo` = ?, `PttTitleSetNo` = ?, TitleSetNo = ? WHERE `DVDPTTVMGKey` = ? AND `PttChapterNo` = ? ;";
                    $stmt = $mysqli->prepare($strSQL);
                    if (!$stmt) {
                        $ResponseText = "Error preparing insert statement for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->bind_param("ssiiiiii", $Artist, $Title, $ProgramChainNo, $ProgramNo, $PttTitleSetNo, $TitleSetNo, $idDVDPTTVMG, $PttChapterNo)) {
                        $ResponseText = "Error binding parameters for DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    if (!$stmt->execute()) {
                        $ResponseText = "Error executing statement on DVDPTTVTS table.\nSQL Error: " . $mysqli->error . "\nSQL State: " . $mysqli->sqlstate;
                        $stmt->close();
                        throw new Exception($ResponseText, XMLRESULT_SQL_ERROR);
                    }
                    //$idDVDPTTVTS = $mysqli->insert_id;
                    $stmt->close();
                }
            }
            // DVDVIDEOSTREAM
            foreach ($tagDVDVMGM->DVDVIDEOSTREAM as $tagDVDVIDEOSTREAM) {
                updateVideoStream($mysqli, $tagDVDVIDEOSTREAM, $idDVDVMGM, null);
            }
            // DVDAUDIOSTREAM
            foreach ($tagDVDVMGM->DVDAUDIOSTREAM as $tagDVDAUDIOSTREAM) {
                updateAudioStream($mysqli, $tagDVDAUDIOSTREAM, $idDVDVMGM, null);
            }
            // DVDSUBPICSTREAM
            foreach ($tagDVDVMGM->DVDSUBPICSTREAM as $tagDVDSUBPICSTREAM) {
                updateSubpictureStream($mysqli, $tagDVDSUBPICSTREAM, $idDVDVMGM, null);
            }
            // Fileset
            foreach ($tagDVDVMGM->DVDFILE as $tagDVDFILE) {
                updateFileset($mysqli, $tagDVDFILE, $idDVDVMGM, null);
            }
        }
    }
    // Commit the transaction
    $rs = query_server($mysqli, "COMMIT;");
}