insert() public method

public insert ( $table, $data )
preg_match($regexParseContent, $wikiText, $matches);
$wikiTextToParse = trim($matches[1]);
preg_match_all($regexGroup, $wikiTextToParse, $groupMatches);
$position = 0;
$groupIds = array();
try {
    $database->startTransaction();
    $database->query("DELETE FROM Info");
    $database->query("DELETE FROM InfoGroup");
    $database->query("UPDATE EndpointEntity SET DeltaStartDateTimeUtc = utc_timestamp() WHERE TableName = 'Info';");
    $database->query("UPDATE EndpointEntity SET DeltaStartDateTimeUtc = utc_timestamp() WHERE TableName = 'InfoGroup';");
    foreach ($groupMatches[1] as $id => $group) {
        $groupId = GUID();
        $parts = explode("|", trim($group), 2);
        Log::info(sprintf("Importing Group %s", trim($parts[0])));
        $database->insert("InfoGroup", array("Id" => $groupId, "LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => "0", "Name" => trim($parts[0]), "Description" => trim($parts[1]), "Position" => $position));
        $position++;
        preg_match_all($regexEntry, $groupMatches[2][$id], $entryMatches);
        $epos = 0;
        foreach ($entryMatches[1] as $entryId => $entry) {
            Log::info(sprintf("  Importing Entry %s", trim($entry)));
            $links = [];
            $images = [];
            // Images / Links
            if ($entryMatches[4][$entryId] != "") {
                preg_match_all($regexLinks, $entryMatches[4][$entryId], $linkMatches);
                foreach ($linkMatches[1] as $linkId => $linkTarget) {
                    $linkText = $linkMatches[2][$linkId];
                    if (strtolower($linkText) == "image") {
                        $imageTag = "info:import[" . strtolower($linkTarget) . "]";
                        $existingImageRow = $database->queryFirstRow("SELECT * FROM image WHERE Title=%s", $imageTag);
}
$news = json_decode(file_get_contents('http://6al.de/efsched/getconnews'));
Log::info("Importing ConNews");
try {
    $database->startTransaction();
    foreach ($news as $entry) {
        Log::info(sprintf("Id: %s, Type: %s -> %s", $entry->id, $entry->news->type, $entry->news->title));
        $dbItem = @$database->query("SELECT * FROM Announcement WHERE ExternalId=%s", "connews:" . $entry->id)[0];
        if ($dbItem) {
            $dbItem["ValidFromDateTimeUtc"] = new DateTime($dbItem["ValidFromDateTimeUtc"]);
            $dbItem["ValidUntilDateTimeUtc"] = new DateTime($dbItem["ValidUntilDateTimeUtc"]);
        }
        if ($entry->news->type == "new" || $entry->news->type == "reschedule") {
            $entry->news->valid_until = $entry->date + 60 * 60 * 48;
        }
        $sourceItem = array("ExternalId" => "connews:" . $entry->id, "ValidFrom" => DateTime::createFromFormat('U', $entry->date), "ValidUntil" => DateTime::createFromFormat('U', $entry->news->valid_until), "Area" => ucwords($entry->news->type), "Author" => isset($entry->news->department) ? ucwords($entry->news->department) : "Eurofurence", "Title" => $entry->news->title, "Content" => strip_tags($parsedown->text($entry->news->message)));
        $patchedItem = patch($sourceItem, $dbItem, array("ExternalId" => "ExternalId", "ValidFrom" => "ValidFromDateTimeUtc", "ValidUntil" => "ValidUntilDateTimeUtc", "Area" => "Area", "Author" => "Author", "Title" => "Title", "Content" => "Content"));
        if ($patchedItem) {
            if (!$dbItem) {
                $database->insert("Announcement", $patchedItem);
            } else {
                $database->update("Announcement", $patchedItem, "Id=%s", $dbItem["Id"]);
            }
        }
    }
    $database->commit();
} catch (Exception $e) {
    var_dump($e->getMessage());
    Log::error("Rolling back changes to database");
    $database->rollback();
}
Esempio n. 3
0
 $queries[3] = "\nCREATE TABLE IF NOT EXISTS `notifications` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `title` text NOT NULL,\n  `text` text NOT NULL,\n  `image` text,\n  `time` int(11) NOT NULL,\n  `userID` int(11) unsigned NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=65 ;\n";
 $queries[4] = "\nCREATE TABLE IF NOT EXISTS `pages` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `title` mediumtext NOT NULL,\n  `content` text NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
 $queries[5] = "\nCREATE TABLE IF NOT EXISTS `plugin_data` (\n  `access_key` text NOT NULL,\n  `setting` text NOT NULL,\n  `setting_type` varchar(255) NOT NULL,\n  `setting_value` text NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $queries[6] = "\nCREATE TABLE IF NOT EXISTS `sessions` (\n  `userID` int(11) NOT NULL,\n  `sessionID` text NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $queries[7] = "\nCREATE TABLE IF NOT EXISTS `settings` (\n  `setting` tinytext NOT NULL,\n  `value` tinytext NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $queries[8] = "\nCREATE TABLE IF NOT EXISTS `storage` (\n  `key` text NOT NULL,\n  `var` text NOT NULL,\n  `is_object` varchar(255) NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $queries[9] = "\nCREATE TABLE IF NOT EXISTS `style_data` (\n  `style_main_class` text NOT NULL,\n  `setting` text NOT NULL,\n  `setting_type` varchar(255) NOT NULL,\n  `setting_value` text NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $queries[10] = "\nCREATE TABLE IF NOT EXISTS `users` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(50) NOT NULL,\n  `password` text NOT NULL,\n  `email` varchar(80) NOT NULL,\n  `rank` tinyint(1) NOT NULL,\n  `activated` tinyint(1) NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;\n";
 $queries[11] = "\nCREATE TABLE IF NOT EXISTS `user_activations` (\n  `userID` int(11) NOT NULL,\n  `code` text NOT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n";
 $creds = $_SESSION['mysql_creds'];
 $db = new MeekroDB($creds['host'], $creds['username'], $creds['password'], $creds['database']);
 foreach ($queries as $query) {
     $db->query($query);
 }
 unset($_SESSION['mysql_creds']);
 $db->insert("settings", array("setting" => "website_url", "value" => $_POST['website_url']));
 $db->insert("settings", array("setting" => "website_name", "value" => $_POST['website_name']));
 $db->insert("settings", array("setting" => "website_style", "value" => "monk"));
 $db->insert("settings", array("setting" => "website_email", "value" => $_POST['admin_email']));
 $db->insert("settings", array("setting" => "website_lang", "value" => "en_US"));
 $db->insert("settings", array("setting" => "show_archive", "value" => "true"));
 $conf = new ConfigFile();
 $config = array();
 $config['db'] = array();
 $config['security'] = array();
 $config['db']['name'] = $creds['database'];
 $config['db']['username'] = $creds['username'];
 $config['db']['password'] = $creds['password'];
 $config['db']['server'] = $creds['host'];
 $config['security']['salt_1'] = generateSalt();
 $config['security']['salt_2'] = generateSalt();
}
try {
    $database->startTransaction();
    /* Import Conference Tracks */
    Log::info("Importing Conference Tracks");
    $importConferenceTracks = Enumerable::from($eventQuery->select('$v["conference_track"]')->distinct()->toList());
    $importConferenceRooms = Enumerable::from($eventQuery->select('$v["conference_room"]')->distinct()->toList());
    $dbConferenceTracks = Enumerable::from($database->query("SELECT * FROM EventConferenceTrack"));
    $importConferenceTracks->each(function ($iItem) use($dbConferenceTracks, $database) {
        $dbItem = $dbConferenceTracks->where(function ($a) use($iItem) {
            return $a["Name"] == $iItem;
        })->singleOrDefault();
        $patchedItem = patch(array("Name" => $iItem), $dbItem, array("Name" => "Name"));
        if ($patchedItem) {
            if (!$dbItem) {
                $database->insert("EventConferenceTrack", $patchedItem);
            } else {
                $database->update("EventConferenceTrack", $patchedItem, "Id=%s", $dbItem["Id"]);
            }
        }
    });
    $dbConferenceTracks->where(function ($a) use($importConferenceTracks) {
        return $a["IsDeleted"] == 0 && $importConferenceTracks->where(function ($b) use($a) {
            return $b == $a["Name"];
        })->count() == 0;
    })->each(function ($a) use($database) {
        $database->update("EventConferenceTrack", array("LastChangeDateTimeUtc" => $database->sqleval("utc_timestamp()"), "IsDeleted" => 1), "Id=%s", $a["Id"]);
    });
    $dbConferenceTracks = Enumerable::from($database->query("SELECT * FROM EventConferenceTrack WHERE IsDeleted = 0"));
    Log::info("Importing Conference Rooms");
    $dbConferenceRooms = Enumerable::from($database->query("SELECT * FROM EventConferenceRoom"));
Esempio n. 5
-1
        }
    }
    if (isset($_GET['limit'])) {
        $query .= " LIMIT " . $_GET['limit'] . " ";
    }
    echo json_encode($mdb->query($query));
});
$app->get('/cars/:id', function ($id) {
    $mdb = new MeekroDB();
    echo json_encode($mdb->query("SELECT * FROM cars WHERE id=" . $id));
});
// POST route
$app->post('/cars', function () {
    // add a new car to the collection
    $mdb = new MeekroDB();
    $mdb->insert('cars', $_POST);
});
$_PUT = $app->request->params();
// PUT route
$app->put('/cars/:id', function ($id) use($_PUT) {
    $columns = array('id', 'brand', 'model', 'year', 'cost');
    // Get a list of cars
    $mdb = new MeekroDB();
    $params = array();
    foreach ($columns as $column) {
        if (isset($_PUT[$column])) {
            $params[] = "`" . $column . "` = '" . $_PUT[$column] . "'";
        }
    }
    $query = "UPDATE cars SET " . implode(',', $params) . " WHERE id=" . $id;
    echo json_encode($mdb->query($query));