function save() { if (!$this->id) { $this->load(); } if ($this->id) { print "updating offsetrule " . $this->id . "</br>"; $this->db->update($this->table, array("season_from" => $this->season_from, "season_to" => $this->season_to, "season_offset" => $this->season_offset, "episode_from" => $this->episode_from, "episode_to" => $this->episode_to, "episode_offset" => $this->episode_offset, "absolute_episode_offset" => $this->absolute_episode_offset), array("id" => $this->id)); } else { print "inserting new offsetrule... "; $this->db->insert($this->table, array("map_id" => $this->map_id, "season_from" => $this->season_from, "season_to" => $this->season_to, "season_offset" => $this->season_offset, "episode_from" => $this->episode_from, "episode_to" => $this->episode_to, "episode_offset" => $this->episode_offset, "absolute_episode_offset" => $this->absolute_episode_offset)); $this->id = $this->db->insert_id(); print_query($this->db); print "new id: " . $this->id . "<br>"; } }
} } if (is_string($param)) { $tmp[] = '<span style="background-color:' . $bg_col . ';">' . $param . '</span>'; } else { $tmp[] = '<span style="background-color:' . $bg_col . ';">' . serialize($param) . '</span>'; } } echo implode(', ', $tmp); } echo '</div>' . '</div>'; } echo ahref_js(count($db->queries) . ' sql', "return toggle_el('" . $sql_div . "')"); $show_div = $db->getErrorCount() ? true : false; $css = $show_div ? '' : 'display:none;'; echo '<div id="' . $sql_div . '" style="' . $css . '">'; foreach ($db->queries as $q) { print_query($q); } echo count($db->queries) . ' ' . (count($db->queries) == 1 ? 'query' : 'queries') . ' in ' . round($db->getTotalQueryTime(), 2) . 's<br/>'; echo '<br/>'; echo 'Server: <b>' . $db->getHost() . '</b><br/>'; /* $db_time = Sql::pSelectItem('SELECT NOW()'); $uptime = Sql::pSelectRow('SHOW STATUS WHERE Variable_name = ?', 's', 'Uptime'); echo 'Database server time: <b>'.$db_time.'</b><br/>'; echo 'Web server time: <b>'.sql_datetime( time() ).'</b><br/>'; echo 'Uptime: <b>'.elapsed_seconds($uptime['Value']).'</b><br/>'; */ echo '</div>';
} function print_query($connection, $query) { $result = query($connection, $query); while ($row = $result->fetchAll()) { print json_encode($row) . PHP_EOL; } } $connection = new PDO('mysql:host=' . DB_SERVER, DB_USER, DB_PASS); query($connection, 'drop database if exists ' . DB_NAME); query($connection, 'create database ' . DB_NAME); $connection = new PDO('mysql:dbname=' . DB_NAME . ';host=' . DB_SERVER, DB_USER, DB_PASS); query($connection, 'create table users (id integer, name text, password text)'); query($connection, 'insert into users (id, name, password) values (1, "test", "test")'); query($connection, 'insert into users (id, name, password) values (2, "test2", "test2")'); print_query($connection, 'select * from users'); class DB { private $dbconn; public function __construct($dbname, $dbhost = '127.0.0.1', $dbuser = '******', $dbpass = '') { // also don't catch the error here, let it propagate, you will clearly see // what happend from the original exception message $this->dbconn = new PDO("mysql:host={$dbhost};dbname={$dbname};", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")); } public function insertUnsafe($table, $data) { // again, no need to try / catch here, let the exceptions // do their job // handle errors only in the case you are going to fix them // and not just to ingnore them and 'echo', this can lead to much worse problems
public function editElementProcces() { if (!$this->session->userdata('logged_in')) { redirect('user/login'); } print "<pre>"; print_r($_POST); print "</pre>"; $element_id = $_POST['element_id']; // change main name $element = new SimpleElement($this->oh, $element_id); $element->main_name = $_POST['main_name']; $element->save(); print_query($this->db); unset($_POST['main_name']); //new name and season if ($_POST['newName']) { $season = -1; if ($_POST['newNameSeason'] && $_POST['newNameSeason'] != -1) { $season = $_POST['newNameSeason']; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newName = new Name($this->db); $newName->element_id = $element_id; $newName->name = $_POST['newName']; $newName->season = $newSeason; $newName->save(); unset($_POST['newName']); unset($_POST['newNameSeason']); } foreach ($_POST as $key => $value) { if (strpos($key, "elementLocationNew_") !== false) { $key = explode("_", $key); $location_id = $key[1]; $season = -1; if ($_POST["elementLocationSeasonNew_" . $location_id] && $_POST["elementLocationSeasonNew_" . $location_id] != "all") { $season = $_POST["elementLocationSeasonNew_" . $location_id]; } $seasonSize = -1; if ($_POST["elementLocationSeasonNew_" . $location_id] && $_POST["elementLocationSeasonNew_" . $location_id] != "infinite") { $seasonSize = $_POST["elementLocationSeasonNew_" . $location_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newElementLocation = new ElementLocation($this->db); $newElementLocation->location = new Location($this->db, $location_id); $newElementLocation->element = new Element($this->db, $element_id); $newElementLocation->season = $newSeason; $newElementLocation->identifier = $value; $newElementLocation->seasonsize = $seasonSize; $newElementLocation->save(); unset($_POST[$key]); unset($_POST["elementLocationSeasonNew_" . $location_id]); continue; } if (strpos($key, "location_") !== false) { print "----------------<br>"; $key = explode("_", $key); $elementLocation_id = $key[1]; $oldSeason = $key[2]; if ($value || $_POST["locationSize_" . $elementLocation_id] && $_POST["locationSeason_" . $elementLocation_id]) { $season = -1; if ($_POST["locationSeason_" . $elementLocation_id] && $_POST["locationSeason_" . $elementLocation_id] != "all") { $season = $_POST["locationSeason_" . $elementLocation_id]; } $seasonSize = -1; if ($_POST["locationSize_" . $elementLocation_id] && $_POST["locationSize_" . $elementLocation_id] != "infinite") { $seasonSize = $_POST["locationSize_" . $elementLocation_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newElementLocation = new ElementLocation($this->db, $elementLocation_id); print $newElementLocation->location->name . ": " . $newElementLocation->identifier . "<br>"; $newElementLocation->season = $newSeason; $newElementLocation->identifier = $value; $newElementLocation->seasonsize = $seasonSize; $newElementLocation->save(); } else { $newElementLocation = new ElementLocation($this->db, $elementLocation_id); $newElementLocation->delete(); } continue; } if (strpos($key, "name_") !== false) { print "----------------<br>"; $key = explode("_", $key); $name_id = $key[1]; if ($value) { $season = -1; if ($_POST["nameSeason_" . $name_id] && $_POST["nameSeason_" . $name_id] != "all") { $season = $_POST["nameSeason_" . $name_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newName = new Name($this->db, $name_id); $newName->name = $value; $newName->season = $newSeason; $newName->save(); } else { $newName = new Name($this->db, $name_id); $newName->delete(); } continue; } } if (!isset($_POST['debug'])) { redirect('xem/editElement/' . $element_id); } }